-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type checking problem with generic __init__()
of generic class.
#7369
Comments
I'm experiencing a similar issue, not sure if it's the same issue: 1.
|
@Pwuts, I don't think your issue is the same. If you think you've found a different bug, please file a separate bug report. I'm not able to repro any errors with the code you've provided. However, I will note that your use of |
@erictraut, I may have stripped off a bit too much code in an effort to make a minimum example. I'll test again and submit a new issue. You're right about the warning that |
This is addressed in pyright 1.1.373. |
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: