@@ -24,27 +24,41 @@ def test_unicode_attribute():
2424 from pynamodb.models import Model
2525
2626 class MyModel(Model):
27- my_attr = UnicodeAttribute(null=True)
27+ my_attr = UnicodeAttribute()
28+ my_nullable_attr = UnicodeAttribute(null=True)
2829
29- reveal_type(MyModel.my_attr) # E: Revealed type is 'pynamodb.attributes._NullableAttribute[pynamodb.attributes.UnicodeAttribute, builtins.str]'
30- reveal_type(MyModel().my_attr) # E: Revealed type is 'Union[builtins.str*, None]'
31- MyModel().my_attr.lower() # E: Item "None" of "Optional[str]" has no attribute "lower"
32- """ ) # noqa: E501
30+ reveal_type(MyModel.my_attr) # E: Revealed type is 'pynamodb.attributes.UnicodeAttribute'
31+ reveal_type(MyModel.my_nullable_attr) # E: Revealed type is 'pynamodb.attributes.UnicodeAttribute*'
32+ reveal_type(MyModel().my_attr) # E: Revealed type is 'builtins.str*'
33+ reveal_type(MyModel().my_nullable_attr) # E: Revealed type is 'Union[builtins.str*, None]'
34+
35+ MyModel().my_attr.lower()
36+ MyModel().my_nullable_attr.lower() # E: Item "None" of "Optional[str]" has no attribute "lower"
37+ """ )
3338
3439
35- def test_custom_type ():
40+ def test_custom_attribute ():
3641 assert_mypy_output ("""
3742 from pynamodb.attributes import Attribute
3843 from pynamodb.models import Model
3944
4045 class BinaryAttribute(Attribute[bytes]):
41- pass
46+ def do_something(self) -> None: ...
4247
4348 class MyModel(Model):
44- my_attr = BinaryAttribute(null=True)
45-
46- reveal_type(MyModel().my_attr) # E: Revealed type is 'Union[builtins.bytes*, None]'
47- """ )
49+ my_attr = BinaryAttribute()
50+ my_nullable_attr = BinaryAttribute(null=True)
51+
52+ reveal_type(MyModel.my_attr) # E: Revealed type is '__main__.BinaryAttribute'
53+ reveal_type(MyModel.my_attr.exists) # E: Revealed type is 'def () -> pynamodb.expressions.condition.Exists'
54+ reveal_type(MyModel.my_attr.do_something) # E: Revealed type is 'def ()'
55+ reveal_type(MyModel().my_attr) # E: Revealed type is 'builtins.bytes*'
56+
57+ reveal_type(MyModel.my_nullable_attr) # E: Revealed type is '__main__.BinaryAttribute*'
58+ reveal_type(MyModel.my_nullable_attr.exists) # E: Revealed type is 'def () -> pynamodb.expressions.condition.Exists'
59+ reveal_type(MyModel.my_nullable_attr.do_something) # E: Revealed type is 'def ()'
60+ reveal_type(MyModel().my_nullable_attr) # E: Revealed type is 'Union[builtins.bytes*, None]'
61+ """ ) # noqa: E501
4862
4963
5064def test_unexpected_number_of_nulls ():
0 commit comments