Skip to content

chore: v3 release #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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 @@ -34,7 +34,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
pydantic-version: ["1.10", "2.0"]
sqla-version: ["1.4", "2"]
exclude:
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/configuration/test_example_11.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import List, Union
from typing import Union

from polyfactory.factories import DataclassFactory

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


@dataclass
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/configuration/test_example_4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from asyncio import sleep
from dataclasses import dataclass
from typing import Dict, List
from uuid import UUID

from polyfactory import AsyncPersistenceProtocol, SyncPersistenceProtocol
Expand All @@ -14,7 +13,7 @@ class Person:


# we will use a dictionary to persist values for the example
mock_db: Dict[UUID, Person] = {}
mock_db: dict[UUID, Person] = {}


class SyncPersistenceHandler(SyncPersistenceProtocol[Person]):
Expand All @@ -24,7 +23,7 @@ def save(self, data: Person) -> Person:
mock_db[data.id] = data
return data

def save_many(self, data: List[Person]) -> List[Person]:
def save_many(self, data: list[Person]) -> list[Person]:
# same as for save, here we should store the list in persistence.
# in this case, we use the same dictionary.
for person in data:
Expand All @@ -40,7 +39,7 @@ async def save(self, data: Person) -> Person:
await sleep(0.0001)
return data

async def save_many(self, data: List[Person]) -> List[Person]:
async def save_many(self, data: list[Person]) -> list[Person]:
# same as for the async save, here we should store the list in persistence using async logic.
# we again store in dict, and mock async using sleep.
for person in data:
Expand Down
8 changes: 4 additions & 4 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, Dict, List, Union
from typing import Any, Union
from uuid import UUID

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


class PetFactory(DataclassFactory[Pet]):
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/configuration/test_example_6.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from dataclasses import dataclass
from typing import Tuple

from polyfactory.factories import DataclassFactory


@dataclass
class Owner:
cars: Tuple[str, ...]
cars: tuple[str, ...]


class OwnerFactory(DataclassFactory[Owner]):
Expand Down
8 changes: 4 additions & 4 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, Dict, List, Union
from typing import Any, Union
from uuid import UUID

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


class PersonFactory(DataclassFactory[Person]): ...
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, Dict, List, Union
from typing import Any, Union
from uuid import UUID

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


class PersonFactory(AttrsFactory[Person]): ...
Expand Down
8 changes: 4 additions & 4 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, Dict, List, Union
from typing import Any, Union
from uuid import UUID

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


pet_instance = Pet(name="Roxy", sound="woof woof", species=Species.DOG)
Expand Down
8 changes: 4 additions & 4 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, Dict, List, Union
from typing import Any, Union
from uuid import UUID

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


class PetFactory(DataclassFactory[Pet]):
Expand Down
8 changes: 4 additions & 4 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, Dict, List, Union
from typing import Any, Union
from uuid import UUID

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


class PetFactory(DataclassFactory[Pet]):
Expand Down
8 changes: 4 additions & 4 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, Dict, List, Union
from typing import Any, Union
from uuid import UUID

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


class PetFactory(DataclassFactory[Pet]):
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/fields/test_example_7.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from typing import Any, Dict
from typing import Any

from polyfactory import PostGenerated
from polyfactory.factories import DataclassFactory


def add_timedelta(name: str, values: Dict[str, datetime], *args: Any, **kwargs: Any) -> datetime:
def add_timedelta(name: str, values: dict[str, datetime], *args: Any, **kwargs: Any) -> datetime:
delta = timedelta(days=1)
return values["from_dt"] + delta

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, Dict, List, Union
from typing import Any, Union
from uuid import UUID

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


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

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

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

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/handling_custom_types/test_example_1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Any, Dict, Type
from typing import Any
from uuid import UUID

from polyfactory.factories import DataclassFactory
Expand Down Expand Up @@ -27,7 +27,7 @@ class Person:
# so we need to override the provider map to add it:
class PersonFactory(DataclassFactory[Person]):
@classmethod
def get_provider_map(cls) -> Dict[Type, Any]:
def get_provider_map(cls) -> dict[type, Any]:
providers_map = super().get_provider_map()

return {
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/handling_custom_types/test_example_2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Any, Dict, Generic, Type, TypeVar
from typing import Any, Generic, TypeVar
from uuid import UUID

from polyfactory.factories import DataclassFactory
Expand All @@ -25,7 +25,7 @@ class CustomDataclassFactory(Generic[T], DataclassFactory[T]):
__is_base_factory__ = True

@classmethod
def get_provider_map(cls) -> Dict[Type, Any]:
def get_provider_map(cls) -> dict[type, Any]:
providers_map = super().get_provider_map()

return {
Expand Down
Loading
Loading