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

Enhancement: Add proper typings to create_factory function #358

Closed
g0di opened this issue Sep 14, 2023 · 0 comments · Fixed by #360
Closed

Enhancement: Add proper typings to create_factory function #358

g0di opened this issue Sep 14, 2023 · 0 comments · Fixed by #360
Labels
enhancement New feature or request

Comments

@g0di
Copy link
Contributor

g0di commented Sep 14, 2023

Summary

When using the imperative code style to create factories, the returned factory is not properly type. Objects built with those factories are typed as Any .

Instead, I would the returned factory to be typed accordingly to the actual model passed allowing type checkers and code editors to take advantage of it.

Basic Example

from polyfactory.factories.pydantic_factory import ModelFactory
from pydantic import BaseModel


class Foo(BaseModel):
    foo: int
    bar: str


fac = ModelFactory.create_factory(Foo)

If you check the type of fac here, you'll get: type[BaseFactory[Any]].
I would have instead type[ModelFactory[Foo]]

Drawbacks and Impact

No response

Unresolved questions

I actually tried to do it myself but could not find a suitable solution


Funding

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
Fund with Polar
@g0di g0di added the enhancement New feature or request label Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant