Closed
Description
# test_hashable.py
from typing import List, Set, Hashable
test_int: int = 5
test_hashable: Hashable = test_int
test_list1 = [1, 2, 3]
test_list2: List[Hashable] = test_list1
test_set1: Set[int] = {1, 2, 3}
test_set2: Set[Hashable] = test_set1
def f(key_set: Set[Hashable]) -> None:
pass
f(test_set1)
> mypy .\test_hashable.py
test_hashable.py:7: error: Incompatible types in assignment (expression has type "List[int]", variable has type "List[Hashable]")
test_hashable.py:10: error: Incompatible types in assignment (expression has type "Set[int]", variable has type "Set[Hashable]")
test_hashable.py:15: error: Argument 1 to "f" has incompatible type "Set[int]"; expected "Set[Hashable]"
> mypy -V
mypy 0.701
> python -V
Python 3.7.3
int
itself seems to be recognized as Hashable
correctly since #1746, but collections of Hashable
seems not accepting collections of int
.
Is this behavior expected and I'm doing something wrong? If so, then what type annotaion should I write when I want a collection of dictionary keys?
Metadata
Metadata
Assignees
Labels
No labels