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

feat: add_providers to easily add new type provider #659

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iloveitaly
Copy link

Description

Without modifying the factory class. This enables 3rd party custom types to easily add providers.

@iloveitaly iloveitaly requested a review from guacs as a code owner March 15, 2025 22:03
Copy link
Member

@cofin cofin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Let's let a few other take a look before merging though.

@iloveitaly
Copy link
Author

Friendly reminder on this pull request. Please provide any updates or additional information if needed.

@provinzkraut
Copy link
Member

@adhtruong?

Copy link
Collaborator

@adhtruong adhtruong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change and feature looks good!

Things to update

  • Small copy and formatting update
  • Can docs be updated with an example to allow discoverability? Maybe under docs/usage/configuration?

@@ -184,10 +184,14 @@ class BaseFactory(ABC, Generic[T]):
_factory_type_mapping: ClassVar[dict[Any, type[BaseFactory[Any]]]]
_base_factories: ClassVar[list[type[BaseFactory[Any]]]]

_providers: ClassVar[dict[Any, Callable[[], Any]]]
"List of type providers that apply to all factories"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"List of type providers that apply to all factories"
"""Mapping of type providers that apply to all factories"""

update to match format of other class doc

# Non-public attributes
_extra_providers: dict[Any, Callable[[], Any]] | None = None
"Used to copy providers from once base factory to another dynamically generated factory for a class"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Used to copy providers from once base factory to another dynamically generated factory for a class"
"""Used to copy providers from once base factory to another dynamically generated factory for a class"""

update to match format of other class doc

Without modifying the factory class. This enables 3rd party custom types
to easily add providers.
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/659

@iloveitaly
Copy link
Author

Just a friendly reminder on this pull request! Let me know if there's anything else that needs to be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants