Skip to content

Commit

Permalink
Update ruff (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche authored Jan 12, 2025
1 parent 77f3c75 commit 01e2224
Show file tree
Hide file tree
Showing 31 changed files with 101 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ clean-test: ## remove test and coverage artifacts
rm -fr htmlcov/

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

test: ## run tests quickly with the default Python
Expand Down
37 changes: 19 additions & 18 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ exclude_also = [

[tool.ruff]
src = ["src", "tests"]

[tool.ruff.lint]
select = [
"E", # pycodestyle
"W", # pycodestyle
Expand Down Expand Up @@ -144,7 +146,6 @@ ignore = [
"S101", # assert
"S307", # hands off my eval
"SIM300", # Yoda rocks in asserts
"PGH001", # No eval lol?
"PGH003", # leave my type: ignores alone
"B006", # mutable argument defaults
"DTZ001", # datetimes in tests
Expand Down
12 changes: 6 additions & 6 deletions src/cattr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from .gen import override

__all__ = (
"global_converter",
"unstructure",
"structure",
"structure_attrs_fromtuple",
"structure_attrs_fromdict",
"UnstructureStrategy",
"BaseConverter",
"Converter",
"GenConverter",
"UnstructureStrategy",
"global_converter",
"override",
"structure",
"structure_attrs_fromdict",
"structure_attrs_fromtuple",
"unstructure",
)
from cattrs import global_converter

Expand Down
2 changes: 1 addition & 1 deletion src/cattr/preconf/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

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

__all__ = ["configure_converter", "JsonConverter", "make_converter"]
__all__ = ["JsonConverter", "configure_converter", "make_converter"]
2 changes: 1 addition & 1 deletion src/cattr/preconf/msgpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

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

__all__ = ["configure_converter", "make_converter", "MsgpackConverter"]
__all__ = ["MsgpackConverter", "configure_converter", "make_converter"]
2 changes: 1 addition & 1 deletion src/cattr/preconf/orjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

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

__all__ = ["configure_converter", "make_converter", "OrjsonConverter"]
__all__ = ["OrjsonConverter", "configure_converter", "make_converter"]
2 changes: 1 addition & 1 deletion src/cattr/preconf/pyyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

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

__all__ = ["configure_converter", "make_converter", "PyyamlConverter"]
__all__ = ["PyyamlConverter", "configure_converter", "make_converter"]
2 changes: 1 addition & 1 deletion src/cattr/preconf/tomlkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

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

__all__ = ["configure_converter", "make_converter", "TomlkitConverter"]
__all__ = ["TomlkitConverter", "configure_converter", "make_converter"]
2 changes: 1 addition & 1 deletion src/cattr/preconf/ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

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

__all__ = ["configure_converter", "make_converter", "UjsonConverter"]
__all__ = ["UjsonConverter", "configure_converter", "make_converter"]
16 changes: 8 additions & 8 deletions src/cattrs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@
"Converter",
"ForbiddenExtraKeysError",
"GenConverter",
"IterableValidationError",
"IterableValidationNote",
"SimpleStructureHook",
"StructureHandlerNotFoundError",
"UnstructureStrategy",
"get_structure_hook",
"get_unstructure_hook",
"global_converter",
"IterableValidationError",
"IterableValidationNote",
"override",
"register_structure_hook_func",
"register_structure_hook",
"register_unstructure_hook_func",
"register_structure_hook_func",
"register_unstructure_hook",
"SimpleStructureHook",
"register_unstructure_hook_func",
"structure",
"structure_attrs_fromdict",
"structure_attrs_fromtuple",
"structure",
"StructureHandlerNotFoundError",
"transform_error",
"unstructure",
"UnstructureStrategy",
]

#: The global converter. Prefer creating your own if customizations are required.
Expand Down
18 changes: 7 additions & 11 deletions src/cattrs/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@

__all__ = [
"ANIES",
"adapted_fields",
"fields_dict",
"ExceptionGroup",
"ExtensionsTypedDict",
"TypeAlias",
"adapted_fields",
"fields_dict",
"has",
"is_typeddict",
"TypeAlias",
]

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

def is_union_type(obj):
return (
obj is Union
or isinstance(obj, _UnionGenericAlias)
and obj.__origin__ is Union
return obj is Union or (
isinstance(obj, _UnionGenericAlias) and obj.__origin__ is Union
)

def get_newtype_base(typ: Any) -> Optional[type]:
Expand Down Expand Up @@ -330,10 +328,8 @@ def is_sequence(type: Any) -> bool:
or (
type.__class__ is _GenericAlias
and (
(origin is not tuple)
and is_subclass(origin, TypingSequence)
or origin is tuple
and type.__args__[1] is ...
((origin is not tuple) and is_subclass(origin, TypingSequence))
or (origin is tuple and type.__args__[1] is ...)
)
)
or (origin in (list, deque, AbcMutableSequence, AbcSequence))
Expand Down
14 changes: 7 additions & 7 deletions src/cattrs/cols.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@
from .converters import BaseConverter

__all__ = [
"defaultdict_structure_factory",
"is_any_set",
"is_defaultdict",
"is_frozenset",
"is_namedtuple",
"is_mapping",
"is_set",
"is_namedtuple",
"is_sequence",
"defaultdict_structure_factory",
"is_set",
"iterable_unstructure_factory",
"list_structure_factory",
"namedtuple_structure_factory",
"namedtuple_unstructure_factory",
"namedtuple_dict_structure_factory",
"namedtuple_dict_unstructure_factory",
"mapping_structure_factory",
"mapping_unstructure_factory",
"namedtuple_dict_structure_factory",
"namedtuple_dict_unstructure_factory",
"namedtuple_structure_factory",
"namedtuple_unstructure_factory",
]


Expand Down
18 changes: 9 additions & 9 deletions src/cattrs/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
)
from .types import SimpleStructureHook

__all__ = ["UnstructureStrategy", "BaseConverter", "Converter", "GenConverter"]
__all__ = ["BaseConverter", "Converter", "GenConverter", "UnstructureStrategy"]

T = TypeVar("T")
V = TypeVar("V")
Expand Down Expand Up @@ -165,16 +165,16 @@ class BaseConverter:
"""Converts between structured and unstructured data."""

__slots__ = (
"_unstructure_func",
"_unstructure_attrs",
"_structure_attrs",
"_dict_factory",
"_union_struct_registry",
"_structure_func",
"_prefer_attrib_converters",
"detailed_validation",
"_struct_copy_skip",
"_structure_attrs",
"_structure_func",
"_union_struct_registry",
"_unstruct_copy_skip",
"_unstructure_attrs",
"_unstructure_func",
"detailed_validation",
)

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

__slots__ = (
"omit_if_default",
"_unstruct_collection_overrides",
"forbid_extra_keys",
"omit_if_default",
"type_overrides",
"_unstruct_collection_overrides",
)

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion src/cattrs/disambiguators.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
if TYPE_CHECKING:
from .converters import BaseConverter

__all__ = ["is_supported_union", "create_default_dis_func"]
__all__ = ["create_default_dis_func", "is_supported_union"]


def is_supported_union(typ: Any) -> bool:
Expand Down
12 changes: 6 additions & 6 deletions src/cattrs/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
from ..converters import BaseConverter

__all__ = [
"make_dict_unstructure_fn",
"make_dict_structure_fn",
"make_iterable_unstructure_fn",
"make_dict_structure_fn_from_attrs",
"make_dict_unstructure_fn",
"make_dict_unstructure_fn_from_attrs",
"make_hetero_tuple_unstructure_fn",
"make_mapping_unstructure_fn",
"make_iterable_unstructure_fn",
"make_mapping_structure_fn",
"make_dict_unstructure_fn_from_attrs",
"make_dict_structure_fn_from_attrs",
"make_mapping_unstructure_fn",
]


Expand Down Expand Up @@ -865,7 +865,7 @@ def mapping_unstructure_factory(

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

if unstructure_to is dict or unstructure_to is None and origin is dict:
if unstructure_to is dict or (unstructure_to is None and origin is dict):
if kh is None and val_handler is None:
# Simplest path.
return dict
Expand Down
2 changes: 1 addition & 1 deletion src/cattrs/gen/typeddicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_annots(cl) -> dict[str, Any]:
if TYPE_CHECKING:
from ..converters import BaseConverter

__all__ = ["make_dict_unstructure_fn", "make_dict_structure_fn"]
__all__ = ["make_dict_structure_fn", "make_dict_unstructure_fn"]

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

Expand Down
4 changes: 3 additions & 1 deletion src/cattrs/preconf/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from ..strategies import configure_union_passthrough
from . import is_primitive_enum, literals_with_enums_unstructure_factory, wrap

__all__ = ["JsonConverter", "configure_converter", "make_converter"]

T = TypeVar("T")


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


def configure_converter(converter: BaseConverter):
def configure_converter(converter: BaseConverter) -> None:
"""
Configure the converter for use with the stdlib json module.
Expand Down
4 changes: 3 additions & 1 deletion src/cattrs/preconf/msgpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from ..strategies import configure_union_passthrough
from . import is_primitive_enum, literals_with_enums_unstructure_factory, wrap

__all__ = ["MsgpackConverter", "configure_converter", "make_converter"]

T = TypeVar("T")


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


def configure_converter(converter: BaseConverter):
def configure_converter(converter: BaseConverter) -> None:
"""
Configure the converter for use with the msgpack library.
Expand Down
4 changes: 3 additions & 1 deletion src/cattrs/preconf/orjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from ..strategies import configure_union_passthrough
from . import is_primitive_enum, literals_with_enums_unstructure_factory, wrap

__all__ = ["OrjsonConverter", "configure_converter", "make_converter"]

T = TypeVar("T")


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


def configure_converter(converter: Converter):
def configure_converter(converter: Converter) -> None:
"""
Configure the converter for use with the orjson library.
Expand Down
Loading

0 comments on commit 01e2224

Please sign in to comment.