Class variables?
See original GitHub issueIs it possible to have class variables that are not part of the schema that is parsed by pydantic?
ie:
class MyModel(BaseModel):
# This is part of pydantic
group: str = None
# This is not.
ACTIONS = ['a', 'b', 'c']```
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:18 (15 by maintainers)
Top Results From Across the Web
Class variable - Wikipedia
In class-based, object-oriented programming, a class variable is a variable defined in a class of which a single copy exists, regardless of how...
Read more >What are class variables, instance variables and local ...
Class variables − Class variables also known as static variables are declared with the static keyword in a class, but outside a method, ......
Read more >Understanding Class Members (The Java™ Tutorials ...
Class Variables. When a number of objects are created from the same class blueprint, they each have their own distinct copies of instance...
Read more >Difference between Instance Variable and Class Variable
Class Variable : It is basically a static variable that can be declared anywhere at class level with static. Across different objects, these ......
Read more >Python Class Variables With Examples - PYnative
Class Variables : A class variable is a variable that is declared inside of class, but outside of any instance method or __init__()...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://github.com/samuelcolvin/pydantic/blob/0698384788e78b3353877bc44340a00089ea1d3f/pydantic/main.py#L121
Start the name with
_
or use a function with the@property
decorator.@tiangolo’s suggestion is definitely the most sensible approach and will make sense to anyone coming from django or similar.
However we should definitely implement
ClassVar
.