Thanks to visit codestin.com
Credit goes to github.com

Skip to content

dict type incorrectly converted (widened?) to object via TypeVar and overload #16282

Description

@pgjones

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 #12385 - closest issue I can find.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-join-v-unionUsing join vs. using unions

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions