@@ -35,7 +35,7 @@ class MyModel(Model):
35
35
MyModel.query(12.3)
36
36
MyModel.query(b'123')
37
37
MyModel.query((1, 2, 3))
38
- MyModel.query({'1': '2'}) # E: Argument 1 to "query" of "Model" has incompatible type "Dict[str, str]"; expected "Union[str, bytes, float, Tuple[Any, ...]]"
38
+ MyModel.query({'1': '2'}) # E: Argument 1 to "query" of "Model" has incompatible type "Dict[str, str]"; expected "Union[str, bytes, float, int, Tuple[Any, ...]]"
39
39
40
40
# test conditions
41
41
MyModel.query(123, range_key_condition=(MyModel.my_attr == 5), filter_condition=(MyModel.my_attr == 5))
@@ -150,10 +150,52 @@ class MyModel(Model):
150
150
151
151
reveal_type(MyModel.my_list) # E: Revealed type is 'pynamodb.attributes.ListAttribute[__main__.MyMap]'
152
152
reveal_type(MyModel().my_list) # E: Revealed type is 'builtins.list[__main__.MyMap*]'
153
- reveal_type(MyModel.my_list[0]) # E: Revealed type is 'Any' # E: Value of type "ListAttribute[MyMap]" is not indexable
153
+ reveal_type(MyModel.my_list[0]) # E: Value of type "ListAttribute[MyMap]" is not indexable # E: Revealed type is 'Any'
154
154
reveal_type(MyModel().my_list[0].my_sub_attr) # E: Revealed type is 'builtins.str'
155
155
156
156
# Untyped lists are not well supported yet
157
- reveal_type(MyModel.my_untyped_list[0]) # E: Revealed type is 'Any' # E: Cannot determine type of 'my_untyped_list '
157
+ reveal_type(MyModel.my_untyped_list[0]) # E: Value of type "ListAttribute[Any]" is not indexable # E: Revealed type is 'Any '
158
158
reveal_type(MyModel().my_untyped_list[0].my_sub_attr) # E: Revealed type is 'Any'
159
159
""" )
160
+
161
+
162
+ def test_index_query_scan ():
163
+ assert_mypy_output ("""
164
+ from pynamodb.attributes import NumberAttribute
165
+ from pynamodb.models import Model
166
+ from pynamodb.indexes import GlobalSecondaryIndex
167
+ from pynamodb.pagination import ResultIterator
168
+
169
+ class UntypedIndex(GlobalSecondaryIndex):
170
+ bar = NumberAttribute(hash_key=True)
171
+
172
+ class TypedIndex(GlobalSecondaryIndex[MyModel]):
173
+ bar = NumberAttribute(hash_key=True)
174
+
175
+ class MyModel(Model):
176
+ foo = NumberAttribute(hash_key=True)
177
+ bar = NumberAttribute()
178
+
179
+ untyped_index = UntypedIndex()
180
+ typed_index = TypedIndex()
181
+
182
+ # Ensure old code keeps working
183
+ untyped_result: ResultIterator = MyModel.untyped_index.query(123)
184
+ model: MyModel = next(untyped_result)
185
+ not_model: int = next(untyped_result) # this is legacy behavior so it's "fine"
186
+
187
+ # Allow users to specify which model their indices return
188
+ typed_result: ResultIterator[MyModel] = MyModel.typed_index.query(123)
189
+ my_model = next(typed_result)
190
+ not_model = next(typed_result) # E: Incompatible types in assignment (expression has type "MyModel", variable has type "int")
191
+
192
+ # Ensure old code keeps working
193
+ untyped_result = MyModel.untyped_index.scan()
194
+ model = next(untyped_result)
195
+ not_model = next(untyped_result) # this is legacy behavior so it's "fine"
196
+
197
+ # Allow users to specify which model their indices return
198
+ untyped_result = MyModel.typed_index.scan()
199
+ model = next(untyped_result)
200
+ not_model = next(untyped_result) # E: Incompatible types in assignment (expression has type "MyModel", variable has type "int")
201
+ """ )
0 commit comments