@@ -14,13 +14,13 @@ class MyModel(Model):
14
14
reveal_type(MyModel().my_not_nullable_attr) # N: Revealed type is 'builtins.float*'
15
15
16
16
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]
18
18
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]
20
20
my_model.my_attr = 42
21
21
my_model.my_nullable_attr = 42
22
22
my_model.my_not_nullable_attr = 42
23
- """ )
23
+ """ ) # noqa: E501
24
24
25
25
26
26
def test_unicode_attribute (assert_mypy_output ):
@@ -42,6 +42,25 @@ class MyModel(Model):
42
42
""" )
43
43
44
44
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
+
45
64
def test_custom_attribute (assert_mypy_output ):
46
65
assert_mypy_output ("""
47
66
from pynamodb.attributes import Attribute
0 commit comments