@@ -14,13 +14,13 @@ class MyModel(Model):
1414 reveal_type(MyModel().my_not_nullable_attr) # N: Revealed type is 'builtins.float*'
1515
1616 my_model = MyModel()
17- my_model.my_attr = None
17+ my_model.my_attr = None # E: Incompatible types in assignment (expression has type "None", variable has type "float") [assignment]
1818 my_model.my_nullable_attr = None
19- my_model.my_not_nullable_attr = None
19+ my_model.my_not_nullable_attr = None # E: Incompatible types in assignment (expression has type "None", variable has type "float") [assignment]
2020 my_model.my_attr = 42
2121 my_model.my_nullable_attr = 42
2222 my_model.my_not_nullable_attr = 42
23- """ )
23+ """ ) # noqa: E501
2424
2525
2626def test_unicode_attribute (assert_mypy_output ):
@@ -42,6 +42,25 @@ class MyModel(Model):
4242 """ )
4343
4444
45+ def test_map_attribute (assert_mypy_output ):
46+ assert_mypy_output ("""
47+ from pynamodb.attributes import MapAttribute, UnicodeAttribute
48+ from pynamodb.models import Model
49+
50+ class MyMapAttribute(MapAttribute):
51+ my_sub_attr = UnicodeAttribute()
52+
53+ class MyModel(Model):
54+ my_attr = MyMapAttribute()
55+ my_nullable_attr = MyMapAttribute(null=True)
56+
57+ reveal_type(MyModel.my_attr) # N: Revealed type is '__main__.MyMapAttribute'
58+ reveal_type(MyModel.my_nullable_attr) # N: Revealed type is '__main__.MyMapAttribute[None]'
59+ reveal_type(MyModel().my_attr) # N: Revealed type is '__main__.MyMapAttribute'
60+ reveal_type(MyModel().my_nullable_attr) # N: Revealed type is 'Union[__main__.MyMapAttribute[None], None]'
61+ """ )
62+
63+
4564def test_custom_attribute (assert_mypy_output ):
4665 assert_mypy_output ("""
4766 from pynamodb.attributes import Attribute
0 commit comments