mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
Add __values__ property with deprecation warning and test for it
This commit is contained in:
@@ -656,6 +656,11 @@ class BaseModel(metaclass=MetaModel):
|
||||
ret.extend(self.__dict__.keys())
|
||||
return ret
|
||||
|
||||
@property
|
||||
def __values__(self) -> 'DictStrAny':
|
||||
warnings.warn('`__values__` attribute is deprecated, use `__dict__` instead', DeprecationWarning)
|
||||
return self.__dict__
|
||||
|
||||
|
||||
def create_model(
|
||||
model_name: str,
|
||||
|
||||
@@ -995,3 +995,13 @@ def test_nested_init(model):
|
||||
assert m.self == 'Top Model'
|
||||
assert m.nest.self == 'Nested Model'
|
||||
assert m.nest.modified_number == 1
|
||||
|
||||
|
||||
def test_values_attr_deprecation():
|
||||
class Model(BaseModel):
|
||||
foo: int
|
||||
bar: str
|
||||
|
||||
m = Model(foo=4, bar='baz')
|
||||
with pytest.warns(DeprecationWarning, match='`__values__` attribute is deprecated, use `__dict__` instead'):
|
||||
assert m.__values__ == m.__dict__
|
||||
|
||||
Reference in New Issue
Block a user