Type checking problem with generic __init__()
of generic class.
#7369
Labels
bug
Something isn't working
__init__()
of generic class.
#7369
Describe the bug
I'm trying to write a generic container class
Container[T]
, and support methoddo_map(self, func: Callable[[T], W]) -> Container[W]
that do a transform likemap()
.For some reasons, I want the the
__init__
to accept alist[U]
and a functionCallable[[U], T]
, and callmap()
in the__init__
.Then the
do_map()
method just need to call the construction of the new container with typeContainer[W]
.However, the following code (
Container0
) is rejected by pyright, but mypy accepts it.Although I can bypass it by a helper function (
Container1
withdo_map_helper
), it's not convenient, and seems like a bug.Code or Screenshots
The type info of the
Container0
in thedo_map()
function seems right, but the type check of argument and parameter report error:If your code relies on symbols that are imported from a third-party library, include the associated import statements and specify which versions of those libraries you have installed.
VS Code extension or command-line
This problem can be reproduced by both Pylance and pyright command-line.
The text was updated successfully, but these errors were encountered: