Skip to content

Commit

Permalink
fix: properly type hint create_factory (#360)
Browse files Browse the repository at this point in the history
* fix: properly type hint create_factory

* docs: ignore 'F' generic type when building docs
  • Loading branch information
guacs authored Sep 16, 2023
1 parent fc0bf61 commit 2a20513
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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],
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

0 comments on commit 2a20513

Please sign in to comment.