Skip to content

Commit 01e2224

Browse files
authored
Update ruff (#621)
1 parent 77f3c75 commit 01e2224

31 files changed

+101
-94
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ clean-test: ## remove test and coverage artifacts
4848
rm -fr htmlcov/
4949

5050
lint: ## check style with ruff and black
51-
pdm run ruff src/ tests bench
51+
pdm run ruff check src/ tests bench
5252
pdm run black --check src tests docs/conf.py
5353

5454
test: ## run tests quickly with the default Python

pdm.lock

Lines changed: 19 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ exclude_also = [
116116

117117
[tool.ruff]
118118
src = ["src", "tests"]
119+
120+
[tool.ruff.lint]
119121
select = [
120122
"E", # pycodestyle
121123
"W", # pycodestyle
@@ -144,7 +146,6 @@ ignore = [
144146
"S101", # assert
145147
"S307", # hands off my eval
146148
"SIM300", # Yoda rocks in asserts
147-
"PGH001", # No eval lol?
148149
"PGH003", # leave my type: ignores alone
149150
"B006", # mutable argument defaults
150151
"DTZ001", # datetimes in tests

src/cattr/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
from .gen import override
33

44
__all__ = (
5-
"global_converter",
6-
"unstructure",
7-
"structure",
8-
"structure_attrs_fromtuple",
9-
"structure_attrs_fromdict",
10-
"UnstructureStrategy",
115
"BaseConverter",
126
"Converter",
137
"GenConverter",
8+
"UnstructureStrategy",
9+
"global_converter",
1410
"override",
11+
"structure",
12+
"structure_attrs_fromdict",
13+
"structure_attrs_fromtuple",
14+
"unstructure",
1515
)
1616
from cattrs import global_converter
1717

src/cattr/preconf/json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from cattrs.preconf.json import JsonConverter, configure_converter, make_converter
44

5-
__all__ = ["configure_converter", "JsonConverter", "make_converter"]
5+
__all__ = ["JsonConverter", "configure_converter", "make_converter"]

src/cattr/preconf/msgpack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from cattrs.preconf.msgpack import MsgpackConverter, configure_converter, make_converter
44

5-
__all__ = ["configure_converter", "make_converter", "MsgpackConverter"]
5+
__all__ = ["MsgpackConverter", "configure_converter", "make_converter"]

src/cattr/preconf/orjson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from cattrs.preconf.orjson import OrjsonConverter, configure_converter, make_converter
44

5-
__all__ = ["configure_converter", "make_converter", "OrjsonConverter"]
5+
__all__ = ["OrjsonConverter", "configure_converter", "make_converter"]

src/cattr/preconf/pyyaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from cattrs.preconf.pyyaml import PyyamlConverter, configure_converter, make_converter
44

5-
__all__ = ["configure_converter", "make_converter", "PyyamlConverter"]
5+
__all__ = ["PyyamlConverter", "configure_converter", "make_converter"]

src/cattr/preconf/tomlkit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from cattrs.preconf.tomlkit import TomlkitConverter, configure_converter, make_converter
44

5-
__all__ = ["configure_converter", "make_converter", "TomlkitConverter"]
5+
__all__ = ["TomlkitConverter", "configure_converter", "make_converter"]

src/cattr/preconf/ujson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from cattrs.preconf.ujson import UjsonConverter, configure_converter, make_converter
44

5-
__all__ = ["configure_converter", "make_converter", "UjsonConverter"]
5+
__all__ = ["UjsonConverter", "configure_converter", "make_converter"]

src/cattrs/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@
2222
"Converter",
2323
"ForbiddenExtraKeysError",
2424
"GenConverter",
25+
"IterableValidationError",
26+
"IterableValidationNote",
27+
"SimpleStructureHook",
28+
"StructureHandlerNotFoundError",
29+
"UnstructureStrategy",
2530
"get_structure_hook",
2631
"get_unstructure_hook",
2732
"global_converter",
28-
"IterableValidationError",
29-
"IterableValidationNote",
3033
"override",
31-
"register_structure_hook_func",
3234
"register_structure_hook",
33-
"register_unstructure_hook_func",
35+
"register_structure_hook_func",
3436
"register_unstructure_hook",
35-
"SimpleStructureHook",
37+
"register_unstructure_hook_func",
38+
"structure",
3639
"structure_attrs_fromdict",
3740
"structure_attrs_fromtuple",
38-
"structure",
39-
"StructureHandlerNotFoundError",
4041
"transform_error",
4142
"unstructure",
42-
"UnstructureStrategy",
4343
]
4444

4545
#: The global converter. Prefer creating your own if customizations are required.

src/cattrs/_compat.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848

4949
__all__ = [
5050
"ANIES",
51-
"adapted_fields",
52-
"fields_dict",
5351
"ExceptionGroup",
5452
"ExtensionsTypedDict",
53+
"TypeAlias",
54+
"adapted_fields",
55+
"fields_dict",
5556
"has",
5657
"is_typeddict",
57-
"TypeAlias",
5858
]
5959

6060
try:
@@ -281,10 +281,8 @@ def get_newtype_base(typ: Any) -> Optional[type]:
281281
from typing_extensions import NotRequired, Required
282282

283283
def is_union_type(obj):
284-
return (
285-
obj is Union
286-
or isinstance(obj, _UnionGenericAlias)
287-
and obj.__origin__ is Union
284+
return obj is Union or (
285+
isinstance(obj, _UnionGenericAlias) and obj.__origin__ is Union
288286
)
289287

290288
def get_newtype_base(typ: Any) -> Optional[type]:
@@ -330,10 +328,8 @@ def is_sequence(type: Any) -> bool:
330328
or (
331329
type.__class__ is _GenericAlias
332330
and (
333-
(origin is not tuple)
334-
and is_subclass(origin, TypingSequence)
335-
or origin is tuple
336-
and type.__args__[1] is ...
331+
((origin is not tuple) and is_subclass(origin, TypingSequence))
332+
or (origin is tuple and type.__args__[1] is ...)
337333
)
338334
)
339335
or (origin in (list, deque, AbcMutableSequence, AbcSequence))

src/cattrs/cols.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,22 @@
4646
from .converters import BaseConverter
4747

4848
__all__ = [
49+
"defaultdict_structure_factory",
4950
"is_any_set",
5051
"is_defaultdict",
5152
"is_frozenset",
52-
"is_namedtuple",
5353
"is_mapping",
54-
"is_set",
54+
"is_namedtuple",
5555
"is_sequence",
56-
"defaultdict_structure_factory",
56+
"is_set",
5757
"iterable_unstructure_factory",
5858
"list_structure_factory",
59-
"namedtuple_structure_factory",
60-
"namedtuple_unstructure_factory",
61-
"namedtuple_dict_structure_factory",
62-
"namedtuple_dict_unstructure_factory",
6359
"mapping_structure_factory",
6460
"mapping_unstructure_factory",
61+
"namedtuple_dict_structure_factory",
62+
"namedtuple_dict_unstructure_factory",
63+
"namedtuple_structure_factory",
64+
"namedtuple_unstructure_factory",
6565
]
6666

6767

src/cattrs/converters.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
)
9898
from .types import SimpleStructureHook
9999

100-
__all__ = ["UnstructureStrategy", "BaseConverter", "Converter", "GenConverter"]
100+
__all__ = ["BaseConverter", "Converter", "GenConverter", "UnstructureStrategy"]
101101

102102
T = TypeVar("T")
103103
V = TypeVar("V")
@@ -165,16 +165,16 @@ class BaseConverter:
165165
"""Converts between structured and unstructured data."""
166166

167167
__slots__ = (
168-
"_unstructure_func",
169-
"_unstructure_attrs",
170-
"_structure_attrs",
171168
"_dict_factory",
172-
"_union_struct_registry",
173-
"_structure_func",
174169
"_prefer_attrib_converters",
175-
"detailed_validation",
176170
"_struct_copy_skip",
171+
"_structure_attrs",
172+
"_structure_func",
173+
"_union_struct_registry",
177174
"_unstruct_copy_skip",
175+
"_unstructure_attrs",
176+
"_unstructure_func",
177+
"detailed_validation",
178178
)
179179

180180
def __init__(
@@ -1020,10 +1020,10 @@ class Converter(BaseConverter):
10201020
"""A converter which generates specialized un/structuring functions."""
10211021

10221022
__slots__ = (
1023-
"omit_if_default",
1023+
"_unstruct_collection_overrides",
10241024
"forbid_extra_keys",
1025+
"omit_if_default",
10251026
"type_overrides",
1026-
"_unstruct_collection_overrides",
10271027
)
10281028

10291029
def __init__(

src/cattrs/disambiguators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
if TYPE_CHECKING:
2727
from .converters import BaseConverter
2828

29-
__all__ = ["is_supported_union", "create_default_dis_func"]
29+
__all__ = ["create_default_dis_func", "is_supported_union"]
3030

3131

3232
def is_supported_union(typ: Any) -> bool:

src/cattrs/gen/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
from ..converters import BaseConverter
4040

4141
__all__ = [
42-
"make_dict_unstructure_fn",
4342
"make_dict_structure_fn",
44-
"make_iterable_unstructure_fn",
43+
"make_dict_structure_fn_from_attrs",
44+
"make_dict_unstructure_fn",
45+
"make_dict_unstructure_fn_from_attrs",
4546
"make_hetero_tuple_unstructure_fn",
46-
"make_mapping_unstructure_fn",
47+
"make_iterable_unstructure_fn",
4748
"make_mapping_structure_fn",
48-
"make_dict_unstructure_fn_from_attrs",
49-
"make_dict_structure_fn_from_attrs",
49+
"make_mapping_unstructure_fn",
5050
]
5151

5252

@@ -865,7 +865,7 @@ def mapping_unstructure_factory(
865865

866866
lines = [f"def {fn_name}(mapping):"]
867867

868-
if unstructure_to is dict or unstructure_to is None and origin is dict:
868+
if unstructure_to is dict or (unstructure_to is None and origin is dict):
869869
if kh is None and val_handler is None:
870870
# Simplest path.
871871
return dict

src/cattrs/gen/typeddicts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_annots(cl) -> dict[str, Any]:
4545
if TYPE_CHECKING:
4646
from ..converters import BaseConverter
4747

48-
__all__ = ["make_dict_unstructure_fn", "make_dict_structure_fn"]
48+
__all__ = ["make_dict_structure_fn", "make_dict_unstructure_fn"]
4949

5050
T = TypeVar("T", bound=TypedDict)
5151

src/cattrs/preconf/json.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from ..strategies import configure_union_passthrough
1414
from . import is_primitive_enum, literals_with_enums_unstructure_factory, wrap
1515

16+
__all__ = ["JsonConverter", "configure_converter", "make_converter"]
17+
1618
T = TypeVar("T")
1719

1820

@@ -24,7 +26,7 @@ def loads(self, data: Union[bytes, str], cl: type[T], **kwargs: Any) -> T:
2426
return self.structure(loads(data, **kwargs), cl)
2527

2628

27-
def configure_converter(converter: BaseConverter):
29+
def configure_converter(converter: BaseConverter) -> None:
2830
"""
2931
Configure the converter for use with the stdlib json module.
3032

src/cattrs/preconf/msgpack.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from ..strategies import configure_union_passthrough
1313
from . import is_primitive_enum, literals_with_enums_unstructure_factory, wrap
1414

15+
__all__ = ["MsgpackConverter", "configure_converter", "make_converter"]
16+
1517
T = TypeVar("T")
1618

1719

@@ -23,7 +25,7 @@ def loads(self, data: bytes, cl: type[T], **kwargs: Any) -> T:
2325
return self.structure(loads(data, **kwargs), cl)
2426

2527

26-
def configure_converter(converter: BaseConverter):
28+
def configure_converter(converter: BaseConverter) -> None:
2729
"""
2830
Configure the converter for use with the msgpack library.
2931

src/cattrs/preconf/orjson.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from ..strategies import configure_union_passthrough
1818
from . import is_primitive_enum, literals_with_enums_unstructure_factory, wrap
1919

20+
__all__ = ["OrjsonConverter", "configure_converter", "make_converter"]
21+
2022
T = TypeVar("T")
2123

2224

@@ -28,7 +30,7 @@ def loads(self, data: Union[bytes, bytearray, memoryview, str], cl: type[T]) ->
2830
return self.structure(loads(data), cl)
2931

3032

31-
def configure_converter(converter: Converter):
33+
def configure_converter(converter: Converter) -> None:
3234
"""
3335
Configure the converter for use with the orjson library.
3436

0 commit comments

Comments
 (0)