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 👍 |
Viicos
left a comment
There was a problem hiding this comment.
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 |
||||||||||||||||||||||||||||||||||||||||||||||||
Viicos
left a comment
There was a problem hiding this comment.
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! |
sydney-runkle
left a comment
There was a problem hiding this comment.
Great work! Thanks @Viicos for giving some detailed line by line feedback.
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