Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pynamodb/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,11 @@ def _is_attribute_container(self):
# by the `_make_attribute` call during initialization of the containing class.
return 'attribute_values' in self.__dict__

def __repr__(self) -> str:
if self._is_attribute_container():
return AttributeContainer.__repr__(self)
return Attribute.__repr__(self)

def _make_attribute(self):
# WARNING! This function is only intended to be called from the __set_name__ function.
if not self._is_attribute_container():
Expand Down
15 changes: 15 additions & 0 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,21 @@ class TestMapAttribute:
"""
Tests map with str, int, float
"""
@pytest.mark.parametrize('name', ['map_attr', 'raw_map_attr'])
def test_descriptor_repr(self, name: str) -> None:
attributes = AttributeTestModel.get_attributes()
attr = attributes[name]
assert repr(attr) == object.__repr__(attr)
assert object.__repr__(attr) in repr(attributes)

@pytest.mark.parametrize('attr, expected', [
(MapAttribute(), 'MapAttribute()'),
(MapAttribute(value='test'), "MapAttribute(value='test')"),
(AttributeTestMapAttribute(string='test'), "AttributeTestMapAttribute(string='test')"),
])
def test_container_repr(self, attr: MapAttribute, expected: str) -> None:
assert repr(attr) == expected

def test_attribute_children(self):
person_attribute = {
'name': 'Justin',
Expand Down