-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Reorganize BaseModel annotations
#10110
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
Reorganize BaseModel annotations
#10110
Conversation
CodSpeed Performance ReportMerging #10110 will not alter performanceComparing Summary
|
|
Coudn't figure out why tests for python 3.8 failed 👀 |
|
Looks similar to https://github.com/pydantic/pydantic/pull/10104/files, which @Viicos closed. Let's get his feedback here given that he was recently working on this 👍 |
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.
Thanks for giving a shot at this. I decided to close the previous PR as I saw it would require too much changes for a small added value.
However, I think I like the approach taken here.
Note that this is not a full review, I'll go a bit more in depth tomorrow morning.
Regarding the failing test, this is because Python 3.10 changed the way __annotations__ works. Prior to 3.10, __annotations__ would inherit the defined annotations from the base(s) class(es).
I'll take a look at a hopefully easy way to handle this.
BaseModel annotations
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
…kc0506/pydantic into reorganize-basemodel-attributes
|
I forgot we could just clear |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||
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.
Thanks this is looking great. A few more comments. Would be awesome if you could update the description in the Attributes: section as well.
Ideally we should avoid the duplication but we seem to be limited by how mkdocstrings-python handle things :/
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
|
@Viicos Thanks for the detailed suggestions! |
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.
Great work! Thanks @Viicos for giving some detailed line by line feedback.
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.
Awesome @kc0506
Change Summary
As per microsoft/pylance-release#6253, attribute docstrings are recommended to be placed in the top level of the class. I added several changes to #10104 to make tests pass.
The only tests that need to be modified are in
test_type_hints, becausetyping.get_type_hintsdoes not have access to types imported insideif TYPE_CHECKINGblocks. Otherwise, we will have to importpydantic_coreandpydantic.fieldsinpydantic.mainonly for type hint, which seems not ideal.Related issue number
#10104
Checklist