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

Skip to content

TypeDict in bound TypeVar assumes parameter values are of type "object" #8231

Description

@rmorshea

Bug Report?

I may be misunderstanding how TypeVar works, but it seems to me that the following usage with TypeDict should be valid, however I get the error indicated in the comment:

from typing import TypedDict, TypeVar


class Data(TypedDict):
    x: int


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


def f(data: T) -> int:
    return data["x"] + 1  # E: Unsupported operand types for + ("object" and "int")
    

assert f(Data(x=1)) == 2

Report Details

  • have you tried it on master: no
  • what version of MyPy: 0.761
  • what flags are you using: none

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions