From 120af4162999772a2e8e2b6479fc7de06cd7c542 Mon Sep 17 00:00:00 2001 From: Jeff Pinner Date: Wed, 14 Oct 2020 10:51:25 -0700 Subject: [PATCH] mypy --- pynamodb/attributes.py | 5 ++++- tests/test_attributes.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pynamodb/attributes.py b/pynamodb/attributes.py index 5ec25077d..aac476ec0 100644 --- a/pynamodb/attributes.py +++ b/pynamodb/attributes.py @@ -988,7 +988,10 @@ class DynamicMapAttribute(MapAttribute): def __setattr__(self, name, value): # Set attributes via the Attribute descriptor if it exists. - object.__setattr__(self, name, value) if name in self.get_attributes() else super().__setattr__(name, value) + if name in self.get_attributes(): + object.__setattr__(self, name, value) + else: + super().__setattr__(name, value) def serialize(self, values): if not isinstance(values, type(self)): diff --git a/tests/test_attributes.py b/tests/test_attributes.py index 124c6ec4c..7f3d31509 100644 --- a/tests/test_attributes.py +++ b/tests/test_attributes.py @@ -877,13 +877,13 @@ class OuterMapAttribute(MapAttribute): class TestDynamicMapAttribute: - class TestModel(Model): + class CreatedAtTestModel(Model): class CreatedAtMap(DynamicMapAttribute): created_at = UTCDateTimeAttribute() test_map = CreatedAtMap(default=dict) def test_serialize(self): - test_model = TestDynamicMapAttribute.TestModel() + test_model = TestDynamicMapAttribute.CreatedAtTestModel() test_model.test_map.created_at = datetime(2017, 1, 1, tzinfo=timezone.utc) test_model.test_map.foo = 'bar' test_model.test_map.empty = None @@ -899,7 +899,7 @@ def test_deserialize(self): 'foo': {'S': 'bar'}, 'empty': {'NULL': True}, }}} - test_model = TestDynamicMapAttribute.TestModel() + test_model = TestDynamicMapAttribute.CreatedAtTestModel() test_model.deserialize(serialized) assert test_model.test_map.created_at == datetime(2017, 1, 1, tzinfo=timezone.utc) assert test_model.test_map.foo == 'bar'