-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
topic-type-contextType context / bidirectional inferenceType context / bidirectional inferencetopic-usability
Description
Bug Report
When you return a function call like return list(...), return dict(...), and the type doesn't match the return annotation, the error message says that list(...) is not valid code.
To Reproduce
def foo() -> list[int]:
tup = ("a", "b", "c")
return list(tup)Expected Behavior
I was expecting mypy to tell me that the type annotation doesn't match the return type.
Instead it says that the arguments to list() are wrong, i.e. list doesn't take this type.
Like so:
$ mypy asd.py
asd.py:3: error: Incompatible return value type (got "List[str]", expected "List[int]") [return-value]
Found 1 error in 1 file (checked 1 source file)Actual Behavior
$ mypy asd.py
asd.py:3: error: Argument 1 to "list" has incompatible type "Tuple[str, str, str]"; expected "Iterable[int]" [arg-type]
Found 1 error in 1 file (checked 1 source file)I think this is misleading.
Your Environment
- Mypy version used: v1.0.1
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.10.9
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
topic-type-contextType context / bidirectional inferenceType context / bidirectional inferencetopic-usability