We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Bug Report
Annotating a generic function which accepts a class name as one of its arguments produces a false negative if that argument has a default.
To Reproduce
class User: # Defines fields like name, email class BasicUser(User): def upgrade(self): """Upgrade to Pro""" class ProUser(User): def pay(self): """Pay bill""" def new_user[U: User](user_class: type[U] = User) -> U: # Error reported here. user = user_class() return user
Expected Behavior
No error should be reported.
Actual Behavior
Mypy reports Incompatible default for argument "user_class" (default has type "type[User]", argument has type "type[U]").
Incompatible default for argument "user_class" (default has type "type[User]", argument has type "type[U]")
The use of the new generic syntax is irrelevant., i.e. the following
from typing import TypeVar U = TypeVar('U', bound=User) def new_user(user_class: type[U] = User) -> U: ...
produces the same error.
Your Environment
mypy.ini
The text was updated successfully, but these errors were encountered:
Duplicate of #3737
Sorry, something went wrong.
No branches or pull requests
Bug Report
Annotating a generic function which accepts a class name as one of its arguments produces a false negative if that argument has a default.
To Reproduce
Expected Behavior
No error should be reported.
Actual Behavior
Mypy reports
Incompatible default for argument "user_class" (default has type "type[User]", argument has type "type[U]")
.The use of the new generic syntax is irrelevant., i.e. the following
produces the same error.
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: