Bug Report
Mypy reasons incorrectly about the return type of collections.deque.copy() if the item type is a generic with a type parameter inside a generic class.
To Reproduce
fromcollectionsimportdequefromtypingimportAny, Callable, Generic, List, Protocol, TypeVarT=TypeVar("T")
deftest(item_type: T) ->None:
a: deque[List[T]] =deque()
b: deque[List[T]] =a.copy() # okclassTest(Generic[T]):
deftest(self) ->None:
a: deque[List[T]] =deque()
b: deque[List[T]] =a.copy() # error: Incompatible types in assignment (expression has type "deque[List[List[T]]]", variable has type "deque[List[T]]") [assignment]Expected Behavior
The return type in the above example should be List[T] not List[List[T]].
Your Environment
Mypy version used: 0.942
Mypy command-line flags: mypy test.py
Mypy configuration options from mypy.ini (and other config files):
[tool.mypy]
strict = truenamespace_packages = trueignore_missing_imports = trueshow_error_codes = trueexclude = "tests"
Python version used: 3.10.2
Operating system and version: OSX 12.2.1 Monterey
Bug Report
Mypy reasons incorrectly about the return type of
collections.deque.copy()if the item type is a generic with a type parameter inside a generic class.To Reproduce
Expected Behavior
The return type in the above example should be
List[T]notList[List[T]].Your Environment
Mypy version used: 0.942
Mypy command-line flags:
mypy test.pyMypy configuration options from
mypy.ini(and other config files):Python version used: 3.10.2
Operating system and version: OSX 12.2.1 Monterey