Skip to content

Commit ebc8590

Browse files
authored
Type-hint hash keys to be Any (#756)
This is needed to correctly type lookups for keys that use UTCDateTimeAttribute, and future-proof further changes.
1 parent b4efd3c commit ebc8590

File tree

2 files changed

+1
-9
lines changed

2 files changed

+1
-9
lines changed

pynamodb/models.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MetaModel(type):
2121
def __init__(self, name: Text, bases: Tuple[type, ...], attrs: Dict[Any, Any]) -> None: ...
2222

2323
_T = TypeVar('_T', bound='Model')
24-
KeyType = Union[Text, bytes, float, int, Tuple]
24+
KeyType = Any
2525

2626
class Model(metaclass=MetaModel):
2727
DoesNotExist = DoesNotExist

tests/test_mypy.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ def test_model_query():
2929
class MyModel(Model):
3030
my_attr = NumberAttribute()
3131
32-
# test hash key types
33-
MyModel.query(123)
34-
MyModel.query('123')
35-
MyModel.query(12.3)
36-
MyModel.query(b'123')
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, int, Tuple[Any, ...]]"
39-
4032
# test conditions
4133
MyModel.query(123, range_key_condition=(MyModel.my_attr == 5), filter_condition=(MyModel.my_attr == 5))
4234

0 commit comments

Comments
 (0)