Skip to content

Commit

Permalink
mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinner-lyft committed Oct 14, 2020
1 parent 1b5e085 commit 120af41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pynamodb/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down

0 comments on commit 120af41

Please sign in to comment.