Skip to content

Commit 1dab01a

Browse files
Migrate from black + pyupgrade to ruff
- Replace black and pyupgrade with ruff-check and ruff-format hooks - Configure ruff with isort (I), bugbear (B), pyupgrade (UP), and pytest-style (PT) rules - Set force-single-line imports for isort - Auto-fix imports and code style with ruff Ruff automatically: - Sorted and organized imports (isort) - Upgraded to modern Python syntax (pyupgrade) - Applied bugbear fixes - Fixed pytest style issues (renamed shadowing variables) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 40f7760 commit 1dab01a

File tree

6 files changed

+54
-43
lines changed

6 files changed

+54
-43
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
repos:
2-
- repo: https://github.com/asottile/pyupgrade
3-
rev: v3.21.0
4-
hooks:
5-
- id: pyupgrade
6-
args: [--py38-plus]
72
- repo: https://github.com/tox-dev/pyproject-fmt
83
rev: "v2.11.0"
94
hooks:
105
- id: pyproject-fmt
116

12-
- repo: https://github.com/psf/black
13-
rev: 25.9.0
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
rev: v0.14.1
149
hooks:
15-
- id: black
16-
language_version: python3
17-
- repo: https://github.com/pre-commit/mirrors-mypy
18-
rev: 'v1.18.2'
19-
hooks:
20-
- id: mypy
21-
args: []
22-
additional_dependencies:
23-
- "pytest==7.2.0"
24-
- "tomli"
10+
- id: ruff-check
11+
args: [--fix]
12+
- id: ruff-format
13+
14+
- repo: https://github.com/pre-commit/mirrors-mypy
15+
rev: 'v1.18.2'
16+
hooks:
17+
- id: mypy
18+
args: []
19+
additional_dependencies:
20+
- "pytest==7.2.0"
21+
- "tomli"

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ iniconfig = [ "py.typed" ]
4646
[tool.setuptools_scm]
4747
write_to = "src/iniconfig/_version.py"
4848

49+
[tool.ruff]
50+
51+
lint.extend-select = [
52+
"B", # flake8-bugbear
53+
"I", # isort
54+
"PT", # flake8-pytest-style
55+
"UP", # pyupgrade
56+
]
57+
lint.isort.force-single-line = true
58+
lint.isort.known-first-party = [ "iniconfig" ]
59+
4960
[tool.pytest.ini_options]
5061
testpaths = "testing"
5162

src/iniconfig/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@
33
"""
44

55
from __future__ import annotations
6-
from typing import (
7-
Callable,
8-
Iterator,
9-
Mapping,
10-
TypeVar,
11-
TYPE_CHECKING,
12-
overload,
13-
)
146

157
import os
8+
from collections.abc import Callable
9+
from collections.abc import Iterator
10+
from collections.abc import Mapping
11+
from typing import TYPE_CHECKING
12+
from typing import TypeVar
13+
from typing import overload
1614

1715
if TYPE_CHECKING:
1816
from typing import Final
1917

2018
__all__ = ["IniConfig", "ParseError", "COMMENTCHARS", "iscommentline"]
2119

22-
from .exceptions import ParseError
2320
from . import _parse
24-
from ._parse import COMMENTCHARS, iscommentline
21+
from ._parse import COMMENTCHARS
22+
from ._parse import iscommentline
23+
from .exceptions import ParseError
2524

2625
_D = TypeVar("_D")
2726
_T = TypeVar("_T")

src/iniconfig/_parse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
2-
from .exceptions import ParseError
32

43
from typing import NamedTuple
54

5+
from .exceptions import ParseError
66

77
COMMENTCHARS = "#;"
88

@@ -70,7 +70,7 @@ def _parseline(path: str, line: str, lineno: int) -> tuple[str | None, str | Non
7070
try:
7171
name, value = line.split(":", 1)
7272
except ValueError:
73-
raise ParseError(path, lineno, "unexpected line: %r" % line)
73+
raise ParseError(path, lineno, f"unexpected line: {line!r}") from None
7474
return name.strip(), value.strip()
7575
# continuation
7676
else:

src/iniconfig/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import annotations
2+
23
from typing import TYPE_CHECKING
34

45
if TYPE_CHECKING:

testing/test_iniconfig.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
from __future__ import annotations
2-
import pytest
3-
from iniconfig import IniConfig, ParseError, __all__ as ALL
4-
from iniconfig._parse import _ParsedLine as PL
5-
from iniconfig import iscommentline
6-
from textwrap import dedent
2+
73
from pathlib import Path
4+
from textwrap import dedent
85

6+
import pytest
7+
8+
from iniconfig import IniConfig
9+
from iniconfig import ParseError
10+
from iniconfig import __all__ as ALL
11+
from iniconfig import iscommentline
12+
from iniconfig._parse import _ParsedLine as PL
913

1014
check_tokens: dict[str, tuple[str, list[PL]]] = {
1115
"section": ("[section]", [PL(0, "section", None, None)]),
@@ -44,7 +48,6 @@
4448

4549
@pytest.fixture(params=sorted(check_tokens))
4650
def input_expected(request: pytest.FixtureRequest) -> tuple[str, list[PL]]:
47-
4851
return check_tokens[request.param]
4952

5053

@@ -214,12 +217,12 @@ def test_config_iter() -> None:
214217
"""
215218
),
216219
)
217-
l = list(config)
218-
assert len(l) == 2
219-
assert l[0].name == "section1"
220-
assert l[0]["value"] == "1"
221-
assert l[1].name == "section2"
222-
assert l[1]["value"] == "2"
220+
sections = list(config)
221+
assert len(sections) == 2
222+
assert sections[0].name == "section1"
223+
assert sections[0]["value"] == "1"
224+
assert sections[1].name == "section2"
225+
assert sections[1]["value"] == "2"
223226

224227

225228
def test_config_contains() -> None:
@@ -251,8 +254,8 @@ def test_iter_file_order() -> None:
251254
b = 2
252255
""",
253256
)
254-
l = list(config)
255-
secnames = [x.name for x in l]
257+
sections_list = list(config)
258+
secnames = [x.name for x in sections_list]
256259
assert secnames == ["section2", "section"]
257260
assert list(config["section2"]) == ["value", "value2"]
258261
assert list(config["section"]) == ["a", "b"]

0 commit comments

Comments
 (0)