diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4b6be3c1..e5f845e6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,7 +37,7 @@ repos: - id: prettier exclude: ".all-contributorsrc" - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.9.0" + rev: "v1.10.0" hooks: - id: mypy exclude: "test_decimal_constraints|examples/fields/test_example_2|examples/configuration|tools/" diff --git a/docs/examples/decorators/test_example_1.py b/docs/examples/decorators/test_example_1.py index b64f90e2..7100b3b3 100644 --- a/docs/examples/decorators/test_example_1.py +++ b/docs/examples/decorators/test_example_1.py @@ -1,6 +1,5 @@ from dataclasses import dataclass, field from datetime import datetime, timedelta -from typing import cast from polyfactory.decorators import post_generated from polyfactory.factories import DataclassFactory @@ -16,7 +15,7 @@ class DatetimeRangeFactory(DataclassFactory[DatetimeRange]): @post_generated @classmethod def to_dt(cls, from_dt: datetime) -> datetime: - return from_dt + cast(timedelta, cls.__faker__.time_delta("+3d")) + return from_dt + cls.__faker__.time_delta("+3d") def test_post_generated() -> None: diff --git a/polyfactory/factories/base.py b/polyfactory/factories/base.py index 60fe7a76..60d32bf7 100644 --- a/polyfactory/factories/base.py +++ b/polyfactory/factories/base.py @@ -505,7 +505,7 @@ def _create_generic_fn() -> Callable: # standard library objects Path: lambda: Path(realpath(__file__)), Decimal: cls.__faker__.pydecimal, - UUID: lambda: UUID(cls.__faker__.uuid4()), + UUID: lambda: UUID(str(cls.__faker__.uuid4())), # datetime datetime: cls.__faker__.date_time_between, date: cls.__faker__.date_this_decade, @@ -777,7 +777,7 @@ def get_field_value_coverage( # noqa: C901 """ if cls.is_ignored_type(field_meta.annotation): - return [None] + return for unwrapped_annotation in flatten_annotation(field_meta.annotation): if unwrapped_annotation in (None, NoneType): diff --git a/polyfactory/factories/beanie_odm_factory.py b/polyfactory/factories/beanie_odm_factory.py index ddd31697..ece683c7 100644 --- a/polyfactory/factories/beanie_odm_factory.py +++ b/polyfactory/factories/beanie_odm_factory.py @@ -29,7 +29,7 @@ class BeaniePersistenceHandler(Generic[T], AsyncPersistenceProtocol[T]): async def save(self, data: T) -> T: """Persist a single instance in mongoDB.""" - return await data.insert() # type: ignore[no-any-return] + return await data.insert() # pyright: ignore[reportGeneralTypeIssues] async def save_many(self, data: list[T]) -> list[T]: """Persist multiple instances in mongoDB. diff --git a/polyfactory/factories/pydantic_factory.py b/polyfactory/factories/pydantic_factory.py index a6028b1c..9499eb16 100644 --- a/polyfactory/factories/pydantic_factory.py +++ b/polyfactory/factories/pydantic_factory.py @@ -484,7 +484,7 @@ def should_set_field_value(cls, field_meta: FieldMeta, **kwargs: Any) -> bool: @classmethod def get_provider_map(cls) -> dict[Any, Callable[[], Any]]: - mapping = { + mapping: dict[Any, Callable[[], Any]] = { pydantic.ByteSize: cls.__faker__.pyint, pydantic.PositiveInt: cls.__faker__.pyint, pydantic.NegativeFloat: lambda: cls.__random__.uniform(-100, -1), diff --git a/polyfactory/value_generators/constrained_dates.py b/polyfactory/value_generators/constrained_dates.py index 4e92601f..8069b05e 100644 --- a/polyfactory/value_generators/constrained_dates.py +++ b/polyfactory/value_generators/constrained_dates.py @@ -1,7 +1,7 @@ from __future__ import annotations from datetime import date, datetime, timedelta, timezone, tzinfo -from typing import TYPE_CHECKING, cast +from typing import TYPE_CHECKING if TYPE_CHECKING: from faker import Faker @@ -38,4 +38,4 @@ def handle_constrained_date( elif lt: end_date = lt - timedelta(days=1) - return cast("date", faker.date_between(start_date=start_date, end_date=end_date)) + return faker.date_between(start_date=start_date, end_date=end_date) diff --git a/tests/test_random_configuration.py b/tests/test_random_configuration.py index dee9e4cf..71e79d11 100644 --- a/tests/test_random_configuration.py +++ b/tests/test_random_configuration.py @@ -1,6 +1,6 @@ from dataclasses import dataclass from random import Random -from typing import List, Union, cast +from typing import List, Union import pytest from faker import Faker @@ -65,7 +65,7 @@ class FooFactory(DataclassFactory[Foo]): @classmethod def foo(cls) -> int: - return cast(int, cls.__faker__.random_digit()) + return cls.__faker__.random_digit() assert FooFactory.build().foo == RANDINT_MAP[seed] diff --git a/tests/test_recursive_models.py b/tests/test_recursive_models.py index b8a0669a..865ea1e8 100644 --- a/tests/test_recursive_models.py +++ b/tests/test_recursive_models.py @@ -53,7 +53,7 @@ def test_recursive_pydantic_models(factory_use_construct: bool) -> None: factory = ModelFactory.create_factory(PydanticNode) result = factory.build(factory_use_construct) - assert result.child is _Sentinel, "Default is not used" + assert result.child is _Sentinel, "Default is not used" # type: ignore[comparison-overlap] assert isinstance(result.union_child, int) assert result.optional_child is None assert result.list_child == []