Skip to content

Commit 8a1d597

Browse files
committed
style: update ruff config and fix lint violations
1 parent f1d7822 commit 8a1d597

File tree

2 files changed

+121
-86
lines changed

2 files changed

+121
-86
lines changed

pyproject.toml

Lines changed: 101 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -101,88 +101,126 @@ warn_unused_configs = true
101101
strict_equality = true
102102
ignore_missing_imports = true
103103

104+
[tool.codespell]
105+
skip = '.git,uv.lock'
106+
104107
[tool.ruff]
105108
line-length = 100
106109

107110
[tool.ruff.lint]
108-
select = [
109-
"F", # Pyflakes
110-
"E", # Pycodestyle (Error)
111-
'I', # isort
112-
'D', # pydocstyle
113-
'D213', # pydocstyle
114-
'UP', # pyupgrade
115-
'YTT', # flake8-2020
116-
'B', # flake8-bugbear
117-
"PLE", # pylint
118-
'PYI006',
119-
'PYI019',
120-
'PYI024',
121-
'PYI030',
122-
'PYI062',
123-
'PYI063',
124-
'PYI066',
125-
"RUF001",
126-
"RUF002",
127-
"RUF003",
128-
"RUF005",
129-
"RUF006",
130-
"RUF012",
131-
"RUF013",
132-
"RUF016",
133-
"RUF017",
134-
"RUF018",
135-
"RUF019",
136-
"RUF020",
137-
"RUF021",
138-
"RUF024",
139-
"RUF026",
140-
"RUF030",
141-
"RUF032",
142-
"RUF033",
143-
"RUF034",
144-
"TRY002",
145-
"TRY004",
146-
"TRY201",
147-
"TRY300",
148-
"TRY301",
149-
"TRY400",
150-
"PERF101",
151-
"RET503",
152-
"LOG001",
153-
"LOG002",
154-
]
111+
select = ["ALL"]
155112
ignore = [
113+
"ERA",
114+
"FBT002",
115+
"COM",
116+
"CPY",
117+
"DJ",
118+
"ANN003",
119+
"FIX",
156120
"D100",
157121
"D101",
158122
"D102",
159123
"D103",
160124
"D104",
161-
'D105',
162-
'D106',
163-
'D107',
164-
'D205',
125+
"D105",
126+
"D106",
127+
"D107",
128+
"D205",
129+
"D203",
165130
"D212",
166-
'D415',
167-
'E501',
168-
'B011',
169-
'B028',
170-
'B904',
171-
'PIE804',
172-
"N802",
173-
"N803",
131+
"E501",
132+
"PIE804",
133+
"S101",
134+
"EM101",
135+
"PYI041",
136+
"PYI051",
137+
"PYI046",
138+
"PYI047",
139+
"PYI049",
140+
"PYI053",
141+
"PYI054",
142+
"RET501",
143+
"SIM910",
144+
"N812",
145+
"PLC0415",
146+
"PLR0904",
147+
"PLR0913",
148+
"PLR2004",
149+
"PLR1711",
150+
"TRY003",
151+
"T20",
152+
"SIM105",
153+
"RET504",
154+
"PLR0912",
155+
"PLR0915",
156+
"SIM105",
157+
"TD",
158+
"TC001",
159+
"TC002",
160+
"TC003",
161+
"TC006",
162+
"PLW0603",
163+
"EM102",
164+
"PLW2901",
165+
"RSE102",
166+
"PGH004",
174167
"N806",
175-
"UP007",
176-
"UP038",
168+
"FBT001",
177169
]
178-
exclude = ["build", "tests/**"]
170+
exclude = ["build"]
179171

180172
[tool.ruff.lint.per-file-ignores]
181173
"__init__.py" = [
182174
"F401", # Unused import
183175
"E402", # Module import not at top of file
184176
]
185-
"method.py" = ["E701"]
177+
"**/tests/**/*.py" = [
178+
"S104",
179+
"S105",
180+
"S106",
181+
"TRY004",
182+
"RUF003",
183+
"RUF012",
184+
"UP031",
185+
"SLF001",
186+
"ARG",
187+
"N806",
188+
"ANN001",
189+
"ANN201",
190+
"ANN202",
191+
"ANN204",
192+
"ANN401",
193+
"S",
194+
"SLF001",
195+
"INP001",
196+
"PLW0108",
197+
"EM102",
198+
"FBT001",
199+
"SIM300",
200+
]
201+
"tests/test_typing.py" = [
202+
"UP006",
203+
"UP007",
204+
"UP035",
205+
]
206+
"examples/*.py" = ["INP001"]
207+
208+
[tool.ruff.lint.pep8-naming]
209+
classmethod-decorators = [
210+
"pydantic.validator",
211+
"declared_attr",
212+
"expression",
213+
"comparator",
214+
]
215+
216+
[tool.ruff.lint.flake8-builtins]
217+
ignorelist = ["id", "input", "classmethod"]
218+
219+
[tool.ruff.lint.flake8-type-checking]
220+
runtime-evaluated-base-classes = [
221+
"pydantic.BaseModel",
222+
"sqlalchemy.orm.DeclarativeBase",
223+
]
186224

187225
[tool.ruff.format]
188226
quote-style = "double"
@@ -195,6 +233,3 @@ known-first-party = ["objinspect", "tests"]
195233

196234
[tool.ruff.lint.pydocstyle]
197235
convention = "google"
198-
199-
[tool.codespell]
200-
skip = '.git,uv.lock'

tests/test_typing.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typing
2-
from collections import OrderedDict, defaultdict, deque
2+
from collections import OrderedDict, defaultdict
33
from enum import Enum, Flag, auto
4-
from typing import Any, Literal
4+
from typing import Any, DefaultDict, Dict, List, Literal, Set, Tuple, Union
55

66
import pytest
77

@@ -111,21 +111,21 @@ def test_is_iterable_type_alias(self):
111111
assert is_iterable_type(tuple[int])
112112

113113
def test_is_iterable_type_typing(self):
114-
assert is_iterable_type(list)
115-
assert is_iterable_type(dict)
114+
assert is_iterable_type(typing.List)
115+
assert is_iterable_type(typing.Dict)
116116
assert is_iterable_type(typing.Sequence)
117-
assert is_iterable_type(set)
118-
assert is_iterable_type(deque)
117+
assert is_iterable_type(typing.Set)
118+
assert is_iterable_type(typing.Deque)
119119

120120

121121
class TestIsMappingType:
122122
def test_is_mapping_type_typing(self):
123123
assert is_mapping_type(OrderedDict)
124124
assert is_mapping_type(defaultdict)
125-
assert is_mapping_type(dict)
125+
assert is_mapping_type(typing.Dict)
126126
assert is_mapping_type(typing.Mapping)
127127
assert is_mapping_type(typing.OrderedDict)
128-
assert is_mapping_type(defaultdict)
128+
assert is_mapping_type(typing.DefaultDict)
129129

130130
def test_is_mapping_type_simple(self):
131131
assert not is_mapping_type(int)
@@ -142,27 +142,27 @@ class TestIsGenericAlias:
142142
@pytest.fixture
143143
def generic_types(self):
144144
return [
145-
list[int],
146-
dict[str, int],
147-
tuple[str, int],
148-
set[float],
149-
list[dict[str, set[int]]],
150-
defaultdict[str, int],
145+
List[int],
146+
Dict[str, int],
147+
Tuple[str, int],
148+
Set[float],
149+
List[Dict[str, Set[int]]],
151150
defaultdict[str, int],
151+
DefaultDict[str, int],
152152
OrderedDict[str, int],
153153
]
154154

155155
def test_positive_cases(self, generic_types):
156156
for type_hint in generic_types:
157-
print(type(list[int]))
158-
print(type(list))
157+
print(type(List[int]))
158+
print(type(List))
159159
assert is_generic_alias(type_hint)
160160

161161
def test_negative_cases(self):
162-
non_generic_types = [int, str, list, dict, int | str, Any]
162+
non_generic_types = [int, str, List, Dict, Union[int, str], Any]
163163
for type_hint in non_generic_types:
164-
print(type(list[int]))
165-
print(type(list))
164+
print(type(List[int]))
165+
print(type(List))
166166
assert not is_generic_alias(type_hint)
167167

168168
def test_custom_generic(self):
@@ -239,7 +239,7 @@ class TestTypeName:
239239
(Any, "Any"),
240240
(typing.Any, "Any"),
241241
(int | str, "int | str"),
242-
(typing.List[int], "List[int]"), # noqa: UP006
242+
(typing.List[int], "List[int]"),
243243
],
244244
)
245245
def test_type_name(self, input_type, expected):

0 commit comments

Comments
 (0)