litestar-org / polyfactory

Simple and powerful factories for mock data generation
https://polyfactory.litestar.dev/
MIT License
988 stars 78 forks source link

feat: add field overrides #519

Closed adhtruong closed 4 months ago

adhtruong commented 5 months ago

Pull Request Checklist

Description

Close Issue(s)

guacs commented 4 months ago

In what scenarios would a user need to do this? Also, couldn't the user just do this directly by specifying a classmethod like in the following:



@dataclass
class Foo:
    foo: int

class FooFactory(DataclassFactory[Foo]):

    @classmethod
    def foo(cls) -> int:
        # Create the value with whatever constraints they may need.
        # They could use the same API that you've used in this PR if they want.
adhtruong commented 4 months ago

Hi @guacs , thanks for review. Definitely needs cleaning up and adding docs and handling for coverage before merging.

My idea mentioned here is making constraints more easy to do. It may be preferable to do it this way so the constraints are handled by the library itself rather than manually specifying. May not be worth the added complexity here as there is an existing way to do this

guacs commented 4 months ago

Yeah my initial instinct is to hold off on this since it's something the user can do themself and not a very common issue I assume.

adhtruong commented 4 months ago

Hold off for now as workaround for functionality.