Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate
ClassVar
s to sub-models (#2179)
* Propagate`ClassVar`s to sub-models Currently, if a `ClassVar` is defined on a model and re-defined on a sub-model omitting the `ClassVar` annotation, Pydantic produces an unrelated error: NameError: Field name "..." shadows a BaseModel attribute ... This check was introduced to prevent shadowing Pydantic's own methods and attributes defined on the `BaseModel` class. Following this change, class variables (that is, variables annotated with `ClassVar`) defined on parent models will be inherited by sub-models and will be overwritable without having to reapply the annotation. Closes #2061. * docs: explain how attributes are excluded and when to use `PrivateAttr`
- Loading branch information
Showing
4 changed files
with
19 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
allow overwriting `ClassVar`s in sub-models without having to re-annotate them |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters