Skip to content

Commit d0edd5e

Browse files
committed
chore: use ruff linter, remove isort
1 parent 371a73c commit d0edd5e

31 files changed

+167
-122
lines changed

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"charliermarsh.ruff",
4+
"esbenp.prettier-vscode",
5+
"ms-python.python"
6+
]
7+
}

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
".eggs": true,
66
"**/*.egg-info": true,
77
".coverage": true,
8+
".mypy_cache": true,
89
".pytest_cache": true,
10+
".ruff_cache": true,
911
".tox": true
1012
},
1113
"editor.detectIndentation": false,
@@ -32,6 +34,5 @@
3234
"python.formatting.provider": "black",
3335
"python.linting.mypyEnabled": true,
3436
"python.linting.pylintEnabled": true,
35-
"python.testing.pytestEnabled": true,
36-
"python.sortImports.args": ["-sp .isort.cfg"]
37+
"python.testing.pytestEnabled": true
3738
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ adheres to [Semantic Versioning](https://semver.org/).
2121
### :house: Internal
2222

2323
- Necessary code changes following dev dependency update: mypy
24+
- Use ruff for linting (and remove isort)
2425

2526
## [0.9.0] - 2022-11-06
2627

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ pytest-cov
1111

1212
# lint
1313
pylint
14+
ruff==0.0.262
1415

1516
# format
1617
black
17-
isort
1818

1919
# publish
2020
setuptools_scm

docs/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
@pytest.fixture(scope="module", autouse=True)
21-
def import_pytest(doctest_namespace: Dict[str, object]) -> None:
21+
def _import_pytest(doctest_namespace: Dict[str, object]) -> None:
2222
doctest_namespace["HandlerTypeHelper"] = HandlerTypeHelper
2323
doctest_namespace["Parser"] = Parser
2424
doctest_namespace["XMLElement"] = XMLElement
@@ -40,7 +40,7 @@ def import_pytest(doctest_namespace: Dict[str, object]) -> None:
4040

4141

4242
@pytest.fixture(scope="module", autouse=True)
43-
def create_files() -> Iterator[None]:
43+
def _create_files() -> Iterator[None]:
4444
cwd = getcwd()
4545
docs_path = Path(__file__).parent
4646
try:

ruff.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
select = ["ALL"]
2+
src = ["src"]
3+
target-version = "py37"
4+
5+
ignore = [
6+
"ANN101",
7+
"ANN102",
8+
"C901",
9+
"COM812",
10+
"D",
11+
"E501",
12+
"EM",
13+
"ERA001",
14+
"PLR0912",
15+
"TRY003",
16+
"TRY301",
17+
]
18+
19+
[per-file-ignores]
20+
"docs/**" = ["D", "INP001", "PTH109"]
21+
"stubs/**" = ["D"]
22+
"tests/**" = ["D", "FBT", "INP001", "PLR2004", "S101", "SLF001"]
23+
24+
[isort]
25+
force-sort-within-sections = true
26+
27+
[flake8-pytest-style]
28+
fixture-parentheses = false
29+
mark-parentheses = false
30+
parametrize-names-type = "list"

src/bigxml/exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class BigXmlError(ValueError):
1010
"""Error parsing XML content"""
1111

12-
def __init__(self, msg: str, security: bool) -> None:
12+
def __init__(self, msg: str, *, security: bool) -> None:
1313
# put only first letter of 'msg' in uppercase
1414
super().__init__(msg[:1].upper() + msg[1:])
1515
self.security = security
@@ -19,12 +19,12 @@ def rewrite_exceptions(iterable: Iterable[T]) -> Iterator[T]:
1919
try:
2020
yield from iterable
2121
except ParseError as ex:
22-
raise BigXmlError(str(ex), False) from ex
22+
raise BigXmlError(str(ex), security=False) from ex
2323
except DefusedXmlException as ex:
2424
# defusedxml has usable wording in it's exception's doc
2525
# except for base DefusedXmlException
2626
msg = (ex.__doc__ or "").strip()
2727
# pylint: disable-next=unidiomatic-typecheck
2828
if not msg or type(ex) is DefusedXmlException:
2929
msg = "Invalid XML"
30-
raise BigXmlError(msg, True) from ex
30+
raise BigXmlError(msg, security=True) from ex

src/bigxml/handle_mgr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ def iter_from(
124124
@overload
125125
def iter_from(
126126
self,
127-
*handlers: Any,
127+
*handlers: Any, # noqa: ANN401
128128
) -> Iterator[object]:
129129
...
130130

131131
def iter_from(self, *handlers: Any) -> Iterator[object]:
132132
if not self._handle:
133133
raise RuntimeError("No handle to use")
134134
handler = create_handler(*handlers)
135-
return self._handle(handler) # pylint: disable=not-callable
135+
return self._handle(handler) # pylint: disable=not-callable
136136

137137
# return_from
138138

src/bigxml/handler_creator.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ def add_handler(
6161
self,
6262
path: Tuple[str, ...],
6363
handler: object,
64+
*,
6465
ignore_direct_marks: bool,
6566
) -> None:
6667
# marked
6768
marks = () if ignore_direct_marks else get_marks(handler)
6869
if marks:
6970
for mark in marks:
70-
self.add_handler(path + mark, handler, True)
71+
self.add_handler(path + mark, handler, ignore_direct_marks=True)
7172
return
7273

7374
# callable
@@ -81,7 +82,7 @@ def add_handler(
8182
if handler_name.startswith("__"):
8283
continue
8384
for sub_path in get_marks(sub_handler):
84-
self.add_handler(path + sub_path, sub_handler, True)
85+
self.add_handler(path + sub_path, sub_handler, ignore_direct_marks=True)
8586
found = True
8687
if found:
8788
return
@@ -95,7 +96,7 @@ def add_handler(
9596
self.add_handler(
9697
path + handler,
9798
_handler_identity,
98-
True, # does not matter as _handler_identity has no marks
99+
ignore_direct_marks=True, # does not matter as _handler_identity has no marks
99100
)
100101
return
101102

@@ -111,8 +112,10 @@ def add_handler_callable(
111112
raise TypeError(f"{self.path}: catchall handler exists: {self.handler}")
112113
if path:
113114
if path[0] not in self.children:
114-
self.children[path[0]] = _HandlerTree(self.path + (path[0],))
115-
self.children[path[0]].add_handler(path[1:], handler, True)
115+
self.children[path[0]] = _HandlerTree((*self.path, path[0]))
116+
self.children[path[0]].add_handler(
117+
path[1:], handler, ignore_direct_marks=True
118+
)
116119
elif self.children:
117120
raise TypeError(f"{self.path}: handlers exist: {self.children}")
118121
else:
@@ -162,7 +165,7 @@ def _handle_from_class( # type: ignore[misc]
162165
sub_tree = _HandlerTree()
163166
items: Iterable[object] = () # empty iterable
164167
try:
165-
sub_tree.add_handler((), instance, True)
168+
sub_tree.add_handler((), instance, ignore_direct_marks=True)
166169
except TypeError:
167170
pass # no marks on public attributes
168171
else:
@@ -205,7 +208,7 @@ def _handle_from_class( # type: ignore[misc]
205208
f" Create a {CLASS_HANDLER_METHOD_NAME}"
206209
" method to handle them properly."
207210
)
208-
warnings.warn(warning_msg, UserWarning)
211+
warnings.warn(warning_msg, UserWarning, stacklevel=1)
209212

210213
if wrapper is None:
211214
# no custom wrapper: only yield instance
@@ -218,5 +221,5 @@ def create_handler(
218221
) -> Callable[[Union["XMLElement", "XMLText"]], Iterator[object]]:
219222
handler_tree = _HandlerTree()
220223
for arg in args:
221-
handler_tree.add_handler((), arg, False)
224+
handler_tree.add_handler((), arg, ignore_direct_marks=False)
222225
return handler_tree.handle

src/bigxml/handler_marker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# plus xml_handle_text can be applied without parenthesis as well
1616

1717

18-
class ___xml_handle_xxx_wrapped(Protocol[T_co]): # pylint: disable=invalid-name
18+
# pylint: disable-next=invalid-name
19+
class ___xml_handle_xxx_wrapped(Protocol[T_co]): # noqa: N801
1920
# wrapper for classes
2021
@overload
2122
def __call__(

0 commit comments

Comments
 (0)