Skip to content

Possible regression in mypy 0.981: Generics don't work when TypeVar are previously used in a TypedDict #13755

Description

@jzazo

Bug Report

When pulling the example of Generics from the documentation and specifying a generic TypedDict following the blog post, I get an error on simple Generic example.

To Reproduce

fromtypingimportGeneric, TypeVarfromtyping_extensionsimportTypedDict# I am using python 3.10.4T=TypeVar("T")
MyDict=TypedDict("MyDict", {"foo": T})
classStack(Generic[T]): # mypy error: Free type variable expected in Generic[...] [misc]def__init__(self) ->None:
pass

Commenting line 5 removes the error. Moving line 5 after the declaration of Stack also works.

Expected Behavior
That class Stack is a correct Generic and mypy should not error.

Your Environment

  • Mypy version used: 0.981
  • Python version used: 3.10.4

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions