-
-
Notifications
You must be signed in to change notification settings - Fork 88
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: Optional __model__
type
#452
feat: Optional __model__
type
#452
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Just a few points regarding the tests and the documentation.
- I think it'd be good to document this behavior as part of this PR itself.
- In the tests, I don't think it's necessary to test that the
build
method works correctly. Instead, a check to see that the__model__
has been set properly is what should be tested since that's the behavior we're concerned about in these tests. - I think the tests can all be moved into one file, and the test for the happy case (i.e. the model is correctly available) can be tested by parameterizing. Something similar to what you've done in
test_model_inference_error.py
.
…ha/polyfactory into feature/enhance-445-optional-model
Thank you for review. All changes within change request were done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mityuha sorry about this, but I wasn't clear in my previous review regarding the documentation. I think we would need to explicitly document this behavior somewhere. That is state explicitly the following:
- users may skip providing the
__model__
IF its type hinted in the generics - users can provide just the
__model__
and not provide the type in the generics - if a
__model__
is provided, then that will be used over whatever the value is given as the generic model type
@guacs OK, not a problem. Where you think is it better to document such behaviour? I would suggest documenting it
Why do I suggest noting this behaviour inside README/index? It's a proven fact that really small number of users read something besides README/index page. So any What do you think? |
This is a good question. Here's what I'm thinking.
Thoughts, @Mityuha? I'd like your opinion as well, @JacobCoffee. |
What I do think is that maybe we want to make life easier by omitting explicit
Me neither. I didn't offer to document all scenarios in the first page. But! I think the appropriate link to all possible scenarios might be useful. But I'm not sure |
@Mityuha you're right. I think this is the better option. So, I'm thinking this is how we can do it:
I'm not sure if the link to the docs regarding the |
@guacs @JacobCoffee Guys, please, check out the new note block in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh, I didn't like the table thing all that too much. It feels like it makes it a bit more complicated than it needs to be. I think it might be simpler to just state that there are two ways of specifying the model type, along with examples of both. Then in a note section, mention that the new syntax is only available from version 2.13.0 onwards.
@guacs It appears that I misunderstood how to deal with it, because you said then
and now
So I thought by But it's OK. I fixed the docs page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mityuha thanks for being patient with me! Everything looks great, and this is a really nice feature that makes things a bit easier for users :)
Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/452 |
@guacs Thank you as well for your review and comments. If I make up my mind -- and if you don't mind -- I will contribute for something else. I have one more idea by the way =) |
Feel free to do so! Also, I'm curious to know what the idea is :) |
Pull Request Checklist
Description
For now you have to specify model type twice: both for a generic type and explicitly for a
__model__
field:This PR adds support for omitting
__model__
field specification:After PR is merged, next PR will be documentation fixes related.
Close Issue(s)
__model__
class field #445