Regression: Unclear error message when using `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
See mypy Playground.
In mypy 1.15 and below, attempting to use Any as an actual type (with instances) gives an unambiguous reason for why it's not valid:
from typing import Any
def get_obj[T](t: type[T], /) -> T: ...
a: int = get_obj(Any) # E: Argument 1 to "get_obj" has incompatible type "<typing special form>"; expected "type[Never]" [arg-type]
In mypy 1.16 this is no longer clear:
a: int = get_obj(Any) # E: Incompatible types in assignment (expression has type "Any", variable has type "int") [assignment]
It looks like mypy now thinks you can create actual instances of typing.Any.
reveal_type(get_obj(Any)) # N: Revealed type is "typing.Any"
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 with the linked mypy Playground example and compare mypy 1.15 with 1.16. Trace how passing typing.Any to get_obj is analyzed and verify the diagnostic and revealed type. Done means the invalid use of Any again produces an unambiguous argument-type error rather than an assignment error claiming the expression has type Any.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100