Skip to content

Commit

Permalink
build: update pre-commit dependencies (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
adhtruong authored Nov 30, 2024
1 parent f526601 commit 9ee5852
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 26 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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/"
Expand All @@ -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"
Expand All @@ -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
2 changes: 1 addition & 1 deletion polyfactory/__metadata__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import importlib.metadata

__all__ = ["__version__", "__project__"]
__all__ = ["__project__", "__version__"]

__version__ = importlib.metadata.version("polyfactory")
"""Version of the project."""
Expand Down
2 changes: 1 addition & 1 deletion polyfactory/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion polyfactory/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion polyfactory/factories/pydantic_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions polyfactory/field_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions polyfactory/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion polyfactory/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]] = {}

Expand Down
2 changes: 1 addition & 1 deletion polyfactory/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion polyfactory/utils/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion polyfactory/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
8 changes: 2 additions & 6 deletions polyfactory/value_generators/constrained_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9ee5852

Please sign in to comment.