Skip to content

Function with generic class and generic value arguments are not inferred when generic is a TypedDict #19201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
frankie567 opened this issue Jun 2, 2025 · 0 comments · May be fixed by #19225
Labels
bug mypy got something wrong topic-typed-dict

Comments

@frankie567
Copy link

Bug Report

When defining a function expecting a generic class and a generic value — tied to the same TypeVar —, mypy is not able to infer the type of the argument if the generic type is a TypedDict.

It works well for scalar types, if the variable is explicitly defined as the typed dict type, or even more surprising, if the first generic argument is binded via a functools.partial.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.12&gist=a6d36519fbd58e5c9b77999eedd16132

import typing
import functools

T = typing.TypeVar("T")


class A(typing.Generic[T]): ...


def f(a: A[T], t: T) -> None: ...


class D(typing.TypedDict):
    x: int


a_typed_dict = A[D]()
f(a_typed_dict, {"x": 1})  # error: Cannot infer type argument 1 of "f"  [misc]

Expected Behavior

The t argument is correctly validated as a D typed dict.

Actual Behavior

The following error message is returned:

error: Cannot infer type argument 1 of "f"  [misc]

Your Environment

  • Mypy version used: 1.15
  • Python version used: 3.12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-typed-dict
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants