diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f33483b0..29edc2ca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,12 +2,12 @@ default_language_version: python: "3" repos: - repo: https://github.com/compilerla/conventional-pre-commit - rev: v3.4.0 + rev: v3.6.0 hooks: - id: conventional-pre-commit stages: [commit-msg] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-ast - id: check-case-conflict @@ -18,11 +18,11 @@ repos: - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/pdm-project/pdm - rev: 2.17.3 + rev: 2.21.0 hooks: - id: pdm-lock-check - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.5.6" + rev: "v0.8.1" hooks: - id: ruff args: ["--fix"] @@ -37,7 +37,7 @@ repos: - id: prettier exclude: ".all-contributorsrc" - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.11.1" + rev: "v1.13.0" hooks: - id: mypy exclude: "test_decimal_constraints|examples/fields/test_example_2|examples/configuration|tools/" @@ -56,7 +56,7 @@ repos: sqlalchemy>=2, ] - repo: https://github.com/RobertCraigie/pyright-python - rev: v1.1.374 + rev: v1.1.389 hooks: - id: pyright exclude: "tests" @@ -75,6 +75,6 @@ repos: sqlalchemy>=2, ] - repo: https://github.com/sphinx-contrib/sphinx-lint - rev: "v0.9.1" + rev: "v1.0.0" hooks: - id: sphinx-lint diff --git a/polyfactory/__metadata__.py b/polyfactory/__metadata__.py index df9b017b..45c71ab7 100644 --- a/polyfactory/__metadata__.py +++ b/polyfactory/__metadata__.py @@ -4,7 +4,7 @@ import importlib.metadata -__all__ = ["__version__", "__project__"] +__all__ = ["__project__", "__version__"] __version__ = importlib.metadata.version("polyfactory") """Version of the project.""" diff --git a/polyfactory/decorators.py b/polyfactory/decorators.py index 88c10219..669b1b39 100644 --- a/polyfactory/decorators.py +++ b/polyfactory/decorators.py @@ -10,7 +10,7 @@ class post_generated: # noqa: N801 """Descriptor class for wrapping a classmethod into a ``PostGenerated`` field.""" - __slots__ = ("method", "cache") + __slots__ = ("cache", "method") def __init__(self, method: Callable | classmethod) -> None: if not isinstance(method, classmethod): diff --git a/polyfactory/factories/__init__.py b/polyfactory/factories/__init__.py index c8a9b925..f8b4981f 100644 --- a/polyfactory/factories/__init__.py +++ b/polyfactory/factories/__init__.py @@ -2,4 +2,4 @@ from polyfactory.factories.dataclass_factory import DataclassFactory from polyfactory.factories.typed_dict_factory import TypedDictFactory -__all__ = ("BaseFactory", "TypedDictFactory", "DataclassFactory") +__all__ = ("BaseFactory", "DataclassFactory", "TypedDictFactory") diff --git a/polyfactory/factories/pydantic_factory.py b/polyfactory/factories/pydantic_factory.py index c65f5454..f881e10d 100644 --- a/polyfactory/factories/pydantic_factory.py +++ b/polyfactory/factories/pydantic_factory.py @@ -350,7 +350,7 @@ def from_model_field( # pragma: no cover return PydanticFieldMeta( name=name, random=random or DEFAULT_RANDOM, - annotation=annotation, + annotation=annotation, # pyright: ignore[reportArgumentType] children=children or None, default=default_value, constraints=cast("PydanticConstraints", {k: v for k, v in constraints.items() if v is not None}) or None, diff --git a/polyfactory/field_meta.py b/polyfactory/field_meta.py index ce262839..8dd0e3d5 100644 --- a/polyfactory/field_meta.py +++ b/polyfactory/field_meta.py @@ -60,7 +60,7 @@ class Constraints(TypedDict): class FieldMeta: """Factory field metadata container. This class is used to store the data about a field of a factory's model.""" - __slots__ = ("name", "annotation", "random", "children", "default", "constraints") + __slots__ = ("annotation", "children", "constraints", "default", "name", "random") annotation: Any random: Random @@ -178,7 +178,7 @@ def parse_constraints(cls, metadata: Sequence[Any]) -> "Constraints": constraints["pattern"] = "[[:ascii:]]" elif func is str.isdigit: constraints["pattern"] = "[[:digit:]]" - elif is_dataclass(value) and (value_dict := asdict(value)) and ("allowed_schemes" in value_dict): # type: ignore[call-overload] + elif is_dataclass(value) and (value_dict := asdict(value)) and ("allowed_schemes" in value_dict): # type: ignore[arg-type] constraints["url"] = {k: v for k, v in value_dict.items() if v is not None} # This is to support `Constraints`, but we can't do a isinstance with `Constraints` since isinstance # checks with `TypedDict` is not supported. diff --git a/polyfactory/fields.py b/polyfactory/fields.py index a3b19eff..b325330d 100644 --- a/polyfactory/fields.py +++ b/polyfactory/fields.py @@ -32,7 +32,7 @@ class Use(Generic[P, T]): """ - __slots__ = ("fn", "kwargs", "args") + __slots__ = ("args", "fn", "kwargs") def __init__(self, fn: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> None: """Wrap a callable. @@ -58,7 +58,7 @@ def to_value(self) -> T: class PostGenerated: """Factory field that allows generating values after other fields are generated by the factory.""" - __slots__ = ("fn", "kwargs", "args") + __slots__ = ("args", "fn", "kwargs") def __init__(self, fn: Callable, *args: Any, **kwargs: Any) -> None: """Designate field as post-generated. @@ -85,7 +85,7 @@ def to_value(self, name: str, values: dict[str, Any]) -> Any: class Fixture: """Factory field to create a pytest fixture from a factory.""" - __slots__ = ("ref", "size", "kwargs") + __slots__ = ("kwargs", "ref", "size") def __init__(self, fixture: Callable, size: int | None = None, **kwargs: Any) -> None: """Create a fixture from a factory. diff --git a/polyfactory/pytest_plugin.py b/polyfactory/pytest_plugin.py index 008f0b13..8b5ec039 100644 --- a/polyfactory/pytest_plugin.py +++ b/polyfactory/pytest_plugin.py @@ -46,7 +46,7 @@ def _get_fixture_name(name: str) -> str: class FactoryFixture: """Decorator that creates a pytest fixture from a factory""" - __slots__ = ("scope", "autouse", "name") + __slots__ = ("autouse", "name", "scope") factory_class_map: ClassVar[dict[Callable, type[BaseFactory[Any]]]] = {} diff --git a/polyfactory/utils/deprecation.py b/polyfactory/utils/deprecation.py index 070e10c9..818e1a71 100644 --- a/polyfactory/utils/deprecation.py +++ b/polyfactory/utils/deprecation.py @@ -7,7 +7,7 @@ from typing_extensions import ParamSpec -__all__ = ("deprecated", "warn_deprecation", "check_for_deprecated_parameters") +__all__ = ("check_for_deprecated_parameters", "deprecated", "warn_deprecation") T = TypeVar("T") diff --git a/polyfactory/utils/predicates.py b/polyfactory/utils/predicates.py index 9ab06c42..4b7d9554 100644 --- a/polyfactory/utils/predicates.py +++ b/polyfactory/utils/predicates.py @@ -126,7 +126,9 @@ def is_any_annotated(annotation: Any) -> bool: :returns: A boolean """ - return any(is_annotated(arg) or hasattr(arg, "__args__") and is_any_annotated(arg) for arg in get_args(annotation)) + return any( + is_annotated(arg) or (hasattr(arg, "__args__") and is_any_annotated(arg)) for arg in get_args(annotation) + ) def get_type_origin(annotation: Any) -> Any: diff --git a/polyfactory/utils/types.py b/polyfactory/utils/types.py index 415f4678..84c8ac84 100644 --- a/polyfactory/utils/types.py +++ b/polyfactory/utils/types.py @@ -28,4 +28,4 @@ def __hash__(self) -> int: # type: ignore[override] return hash(tuple(self.items())) -__all__ = ("NoneType", "UNION_TYPES", "Frozendict") +__all__ = ("UNION_TYPES", "Frozendict", "NoneType") diff --git a/polyfactory/value_generators/constrained_numbers.py b/polyfactory/value_generators/constrained_numbers.py index 4ba43696..3cf77dee 100644 --- a/polyfactory/value_generators/constrained_numbers.py +++ b/polyfactory/value_generators/constrained_numbers.py @@ -362,12 +362,8 @@ def handle_decimal_length( string_number = string_number.replace("-", "") whole_numbers, decimals = string_number.split(".") - if ( - max_digits is not None - and decimal_places is not None - and len(whole_numbers) + decimal_places > max_digits - or (max_digits is None or decimal_places is None) - and max_digits is not None + if (max_digits is not None and decimal_places is not None and len(whole_numbers) + decimal_places > max_digits) or ( + (max_digits is None or decimal_places is None) and max_digits is not None ): max_decimals = max_digits - len(whole_numbers) elif max_digits is not None: