Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
pydantic-version: ["1.10", "2.0"]
sqla-version: ["1.4", "2"]
exclude:
Expand Down
2 changes: 1 addition & 1 deletion .sourcery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rule_settings:
- refactoring
- suggestion
- comment
python_version: "3.8"
python_version: "3.10"

rules: []

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
autodoc_member_order = "bysource"
autodoc_typehints_format = "short"

auto_pytabs_min_version = (3, 8)
auto_pytabs_max_version = (3, 11)
auto_pytabs_min_version = (3, 10)
auto_pytabs_max_version = (3, 14)
auto_pytabs_compat_mode = True

autosectionlabel_prefix_document = True
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/configuration/test_example_11.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Union

from polyfactory.factories import DataclassFactory

# Define a recursive type using forward reference
RecursiveType = Union[list["RecursiveType"], int]
RecursiveType = list["RecursiveType"] | int


@dataclass
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/configuration/test_example_5.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from datetime import date, datetime
from enum import Enum
from typing import Any, Union
from typing import Any
from uuid import UUID

from polyfactory import Use
Expand All @@ -25,8 +25,8 @@ class Person:
id: UUID
name: str
hobbies: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date
pets: list[Pet]
assets: list[dict[str, dict[str, Any]]]

Expand Down
3 changes: 1 addition & 2 deletions docs/examples/configuration/test_example_7.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dataclasses import dataclass
from typing import Optional
from uuid import UUID

from polyfactory.factories.dataclass_factory import DataclassFactory
Expand All @@ -8,7 +7,7 @@
@dataclass
class Person:
id: UUID
name: Optional[str]
name: str | None


class PersonFactory(DataclassFactory[Person]):
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/declaring_factories/test_example_5.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from datetime import date, datetime
from enum import Enum
from typing import Any, Union
from typing import Any
from uuid import UUID

from polyfactory.factories import DataclassFactory
Expand All @@ -24,8 +24,8 @@ class Person:
id: UUID
name: str
hobbies: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date
pets: list[Pet]
assets: list[dict[str, dict[str, Any]]]

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/declaring_factories/test_example_7.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import date, datetime
from typing import Any, Union
from typing import Any
from uuid import UUID

import attrs
Expand All @@ -12,9 +12,9 @@ class Person:
id: UUID
name: str
hobbies: list[str]
age: Union[float, int]
age: float | int
# an aliased variable
birthday: Union[datetime, date] = attrs.field(alias="date_of_birth")
birthday: datetime | date = attrs.field(alias="date_of_birth")
# a "private" variable
_assets: list[dict[str, dict[str, Any]]]

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/fields/test_example_1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from datetime import date, datetime
from enum import Enum
from typing import Any, Union
from typing import Any
from uuid import UUID

from polyfactory.factories import DataclassFactory
Expand All @@ -24,8 +24,8 @@ class Person:
id: UUID
name: str
hobbies: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date
pets: list[Pet]
assets: list[dict[str, dict[str, Any]]]

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/fields/test_example_2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from datetime import date, datetime
from enum import Enum
from typing import Any, Union
from typing import Any
from uuid import UUID

from polyfactory import Use
Expand All @@ -25,8 +25,8 @@ class Person:
id: UUID
name: str
hobbies: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date
pets: list[Pet]
assets: list[dict[str, dict[str, Any]]]

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/fields/test_example_3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from datetime import date, datetime
from enum import Enum
from typing import Any, Union
from typing import Any
from uuid import UUID

from polyfactory import Use
Expand All @@ -25,8 +25,8 @@ class Person:
id: UUID
name: str
hobbies: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date
pets: list[Pet]
assets: list[dict[str, dict[str, Any]]]

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/fields/test_example_4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from datetime import date, datetime
from enum import Enum
from typing import Any, Union
from typing import Any
from uuid import UUID

from polyfactory import Use
Expand All @@ -25,8 +25,8 @@ class Person:
id: UUID
name: str
hobbies: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date
pets: list[Pet]
assets: list[dict[str, dict[str, Any]]]

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/fields/test_example_8.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from datetime import date, datetime
from enum import Enum
from typing import Any, Union
from typing import Any
from uuid import UUID

from polyfactory.factories import DataclassFactory
Expand All @@ -24,8 +24,8 @@ class Person:
id: UUID
name: str
hobbies: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date
pet: Pet
assets: list[dict[str, dict[str, Any]]]

Expand Down
7 changes: 3 additions & 4 deletions docs/examples/fixtures/test_example_1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dataclasses import dataclass
from datetime import date, datetime
from typing import Optional, Union
from uuid import UUID

from polyfactory.factories import DataclassFactory
Expand All @@ -11,10 +10,10 @@
class Person:
id: UUID
name: str
hobbies: Optional[list[str]]
hobbies: list[str] | None
nicks: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date


@register_fixture
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/fixtures/test_example_2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dataclasses import dataclass
from datetime import date, datetime
from typing import Optional, Union
from uuid import UUID

from polyfactory.factories import DataclassFactory
Expand All @@ -11,10 +10,10 @@
class Person:
id: UUID
name: str
hobbies: Optional[list[str]]
hobbies: list[str] | None
nicks: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date


class PersonFactory(DataclassFactory[Person]): ...
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/fixtures/test_example_3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dataclasses import dataclass
from datetime import date, datetime
from typing import Optional, Union
from uuid import UUID

from polyfactory.factories import DataclassFactory
Expand All @@ -11,10 +10,10 @@
class Person:
id: UUID
name: str
hobbies: Optional[list[str]]
hobbies: list[str] | None
nicks: list[str]
age: Union[float, int]
birthday: Union[datetime, date]
age: float | int
birthday: datetime | date


@register_fixture(name="aliased_person_factory")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class User(Base):
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]

user_keyword_associations: Mapped[list["UserKeywordAssociation"]] = relationship(
user_keyword_associations: Mapped[list[UserKeywordAssociation]] = relationship(
back_populates="user",
)
keywords: AssociationProxy[list["Keyword"]] = association_proxy(
keywords: AssociationProxy[list[Keyword]] = association_proxy(
"user_keyword_associations",
"keyword",
creator=lambda keyword_obj: UserKeywordAssociation(keyword=keyword_obj),
Expand All @@ -32,7 +32,7 @@ class UserKeywordAssociation(Base):
keyword_id: Mapped[int] = mapped_column(ForeignKey("keywords.id"), primary_key=True)

user: Mapped[User] = relationship(back_populates="user_keyword_associations")
keyword: Mapped["Keyword"] = relationship()
keyword: Mapped[Keyword] = relationship()


class Keyword(Base):
Expand Down
9 changes: 0 additions & 9 deletions docs/reference/constants.rst

This file was deleted.

10 changes: 0 additions & 10 deletions polyfactory/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
from collections import abc, defaultdict, deque
from collections.abc import Iterable, Mapping, Sequence
from random import Random
from typing import (
Union,
)

try:
from types import UnionType
except ImportError:
UnionType = Union # type: ignore[misc,assignment]


# Mapping of type annotations into concrete types.
TYPE_MAPPING = {
Expand All @@ -29,7 +20,6 @@
abc.Mapping: dict,
abc.Sequence: list,
abc.Set: set,
UnionType: Union,
}


Expand Down
5 changes: 4 additions & 1 deletion polyfactory/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import contextlib
import inspect
from typing import Any, Callable
from typing import TYPE_CHECKING, Any

from polyfactory import PostGenerated

if TYPE_CHECKING:
from collections.abc import Callable


class post_generated: # noqa: N801
"""Descriptor class for wrapping a classmethod into a ``PostGenerated`` field."""
Expand Down
Loading
Loading