You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a developer wants to use various helpers in a given declaration (for instance, having a unique company name), they have to go through unnecessary complicated hoops:
However, this requires us to add more and more building blocks as user needs evolve.
Another option would be to play with method introspection: if the default values of a function's arguments are factory.Declaration subclasses, we could automatically detect it:
Chiming in here from #767 . From an API perspective, the alternative proposal looks the most intuitive to me. Anectodally, I expected RelatedFactoryList(SomeFactory, size=factory.SelfAttribute('foo')) to work because the base object had already been instantiated by the time RelatedFactoryList is called.
The problem
If a developer wants to use various helpers in a given declaration (for instance, having a unique company name), they have to go through unnecessary complicated hoops:
There is no way to pass the result of a
factory.Faker()
call to afactory.Sequence
declaration, for instance.Proposed solution
One option would be to add an extra declaration, for instance:
However, this requires us to add more and more building blocks as user needs evolve.
Another option would be to play with method introspection: if the default values of a function's arguments are
factory.Declaration
subclasses, we could automatically detect it:Summary
Pros:
Cons:
def foo(x=SomeClass(y=factory.Faker('name')))
)Alternative
A possible compromise would be to only inspect the parameters of
factory.Declaration
subclasses:Here, the reader would have an idea that something specific is happening thanks to the
@lazy_attribute
decorator.The text was updated successfully, but these errors were encountered: