@@ -24,27 +24,41 @@ def test_unicode_attribute():
24
24
from pynamodb.models import Model
25
25
26
26
class MyModel(Model):
27
- my_attr = UnicodeAttribute(null=True)
27
+ my_attr = UnicodeAttribute()
28
+ my_nullable_attr = UnicodeAttribute(null=True)
28
29
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
+ """ )
33
38
34
39
35
- def test_custom_type ():
40
+ def test_custom_attribute ():
36
41
assert_mypy_output ("""
37
42
from pynamodb.attributes import Attribute
38
43
from pynamodb.models import Model
39
44
40
45
class BinaryAttribute(Attribute[bytes]):
41
- pass
46
+ def do_something(self) -> None: ...
42
47
43
48
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
48
62
49
63
50
64
def test_unexpected_number_of_nulls ():
0 commit comments