-
-
Notifications
You must be signed in to change notification settings - Fork 72
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: Optional __model__
class field
#445
Comments
@Mityuha yeah, a PR would definitely be welcome if there's a clean way to not have to specify the type twice. That being said, I'm curious as to how you're planning on getting rid of the need to specify Also, I think the aim should be to do it the other way around. By that I mean that instead of attempting to remove the setting of class PersonFactory(DataclassFactory):
__model__ = Person |
Hello, @guacs . Thanks for response. About the way to not specify the generic type: I could be wrong but it seems that the generic type is needed for further type hints. It's a little bit unclear for me how to achieve the same effect (generic class) without Again, I might be mistaken about type hints since I haven't dive deep into the code yet. I think I'm going to try to implement my hypothesis in a clean way and, if I cope with it, I will make a PR. |
You are right.
Yupp this should work. So, I think the solution would be to parse and set the value for
A PR would definitely be appreciated :) |
PR #452 is ready. Please come and check it out |
Added in #452. |
Summary
Hi there.
Thank you for this useful library.
I tried to build some factories and found declaration of
__model__
field a little bit annoyed.Indeed, we already declare the model type in
Generic
params. Perhaps, it's enough.Basic Example
Now we should declare factories this way (from documentation):
My suggestion is getting rid of Base class type declaration by making
__model__
field optional for backward compatibility and/or deprecating it. So thatDrawbacks and Impact
No response
Unresolved questions
I skimmed the source code/documentation quickly and found classmethod
create_factory
. This method allows you to define a factory imperatively.The question is -- is it worth contributing into library to give the opportunity for doing the same declaratively?
If so I'm ready to implement this feature.
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh Litestar dashboard
The text was updated successfully, but these errors were encountered: