Skip to content

Issue with TypedDict bound TypeVar in generic class #11812

@krisz2000

Description

@krisz2000

Bug Report

There seems to be a bug with TypedDict bound TypeVar used in a generic class.

To Reproduce

from typing import Generic, TypeVar, TypedDict


class A(TypedDict):
    a: str


T = TypeVar("T", bound=A)


class G(Generic[T]):
    a: str

    def foo(self, t: T) -> None:
        t["a"] = "asd"
        self.a = t["a"]

    def bar(self) -> T:
        return {"a": self.a}

Actual Behavior
In foo the first line is correct, but the second throws an error:
test.py:16: error: Incompatible types in assignment (expression has type "object", variable has type "str")

Bar throws an error too:
test.py:19: error: Incompatible return value type (got "Dict[str, str]", expected "T")

Am I missing something or is this a bug?

Your Environment

  • Mypy version used: 0.920
  • Mypy command-line flags: none
  • Python version used: 3.9.7

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions