Function declared to return list[int] actually returning list[Any]
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
(A clear and concise description of what the bug is.)
To Reproduce
from typing import Any
def foo() -> list[int]:
x: list[Any] = ["xxx"]
return x
Expected Behavior
I would expect an error on line 6 return x. The function is declared to return list[int] but is returning list[Any].
Actual Behavior
No error.
$ mypy --strict --disallow-any-generics --warn-return-any test.py
Success: no issues found in 1 source file
Your Environment
- Mypy version used: 1.9.0
- Mypy command-line flags:
--strict --disallow-any-generics --warn-return-any - Mypy configuration options from
mypy.ini(and other config files): (none) - Python version used: 3.10.12
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Python example with mypy 1.9.0 and the listed strictness flags, then trace the return-type checking path for list[Any] versus list[int]. Done means the example reports an error at the return statement without breaking related type-checking behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100