Add __values__ property with deprecation warning and test for it

This commit is contained in:
MrMrRobat
2019-08-03 18:05:17 +03:00
parent abd773b5a5
commit bbf0b4bfbe
2 changed files with 15 additions and 0 deletions
+5
View File
@@ -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,
+10
View File
@@ -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__