-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Defining a class method list causes mypy [valid-type] errors #13050
Copy link
Copy link
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
To Reproduce
Consider the following minimal Python class:
class Checks:
def ok(self, input: list[str]) -> None:
pass
def list(self) -> None:
pass
def fail(self, input: list[str]) -> None:
passExpected Behavior
I would expect that running mypy on this class passes just fine.
Actual Behavior
In fact, mypy finds an error:
bug.py:8: error: Function "bug.Checks.list" is not valid as a type [valid-type]
bug.py:8: note: Perhaps you need "Callable[...]" or a callback protocol?
Note that the first method (ok) does not result in an error, while the last method (fail) does. Somehow mypy is confused by the second method being called list. Now it thinks that the type hint list[str] somehow refers to this class method, instead of the built-in generic type.
What is going on here?
Your Environment
- Mypy version used: 0.961
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.9.13
- Operating system and version: WSL Ubuntu 20.04
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong