Skip to content
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

fix: properly type hint create_factory #360

Merged
merged 2 commits into from
Sep 16, 2023
Merged
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
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
(PY_CLASS, "Random"),
(PY_CLASS, "Scope"),
(PY_CLASS, "T"),
(PY_CLASS, "F"),
(PY_CLASS, "P"),
(PY_CLASS, "P.args"),
(PY_CLASS, "P.kwargs"),
Expand Down
9 changes: 5 additions & 4 deletions polyfactory/factories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def _create_pydantic_type_map(cls: type[BaseFactory[Any]]) -> dict[type, Callabl


T = TypeVar("T")
F = TypeVar("F", bound="BaseFactory[Any]")


class BaseFactory(ABC, Generic[T]):
Expand Down Expand Up @@ -487,11 +488,11 @@ def _create_generic_fn() -> Callable:

@classmethod
def create_factory(
cls,
model: type,
cls: type[F],
model: type[T],
guacs marked this conversation as resolved.
Show resolved Hide resolved
bases: tuple[type[BaseFactory[Any]], ...] | None = None,
**kwargs: Any,
) -> type[BaseFactory[Any]]:
) -> type[F]:
"""Generate a factory for the given type dynamically.

:param model: A type to model.
Expand All @@ -502,7 +503,7 @@ def create_factory(

"""
return cast(
"Type[BaseFactory[Any]]",
"Type[F]",
type(
f"{model.__name__}Factory",
(*(bases or ()), cls),
Expand Down
Loading