dict type incorrectly converted (widened?) to object via TypeVar and overload
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
In the snippet below I'd expect the revealed type to be def () -> typing.Awaitable[builtins.dict], not def () -> typing.Awaitable[builtins.object].
To Reproduce
from typing import *
P = ParamSpec("P")
T = TypeVar("T")
@overload
def ensure_async(f: Callable[P, Awaitable[T]])-> Callable[P, Awaitable[T]]: ...
@overload
def ensure_async(f: Callable[P, T])-> Callable[P, Awaitable[T]]: ...
def ensure_async(f):
...
async def a() -> None:
g: Callable[[], dict] | Callable[[], Awaitable[dict]]
reveal_type(ensure_async(g))
https://mypy-play.net/?mypy=master&python=3.12&gist=f596993883d9235e669e38dbe212909e
Actual Behavior
main.py:18: note: Revealed type is "def () -> typing.Awaitable[builtins.object]"
Your Environment
- Mypy version used: 1.6 or master
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.12
This may be related to https://github.com/python/mypy/issues/12385 - closest issue I can find.
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 provided Python reproducer in mypy-play and confirm the revealed type on the current mypy version. Trace overload resolution and TypeVar inference for the union of callable signatures; done means the result is reported as Callable[[], Awaitable[dict]] rather than Awaitable[object], with a regression test covering the case.
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