Skip to content

"Subset" of TypedDict in not accepted in TypedDict.update #6249

@SebbyLaw

Description

@SebbyLaw

Hello again. This was introduced from pyright 1.1.332 -> pyright 1.1.333
For real this time :trollface:

Describe the bug

A "subset" TypedDict can't be passed into the dict.update function of a "superset" TypedDict
e.g: the fields & annotations of the "subset" TypedDict are a subset of the fields & annotations of the "superset" TypedDict

Code or Screenshots

Here's the code in pyright playground: https://pyright-play.net/?pyrightVersion=1.1.333&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAqiApgCYAiSAxjAFD1UA2AhgM6tQBiYYAFEQjKUaASgBctKFKjMxmFHWlQARnNYwQk6VTnBGYZnQYt2UAELMQ-EhWoxxWqbPmLpqqOs31gPKAF4uHl5mPwBGABoVPwAiACZoyKo-AGYAOgAGEXplS39zS2Cw9MjlGNj06KzvHlSAVwRSQ2JeHJARKQBiKGIQcE0fMDqGpt4Ab2jmaLlQ4qho5Sm58uiAX3aoLpQwbt7cWiA

And below for visibility:

from typing import TypedDict


class Foo(TypedDict):
    a: int
    b: str
    c: float


class Bar(TypedDict):
    a: int
    b: str


foo = Foo(a=1, b="2", c=3.0)

bar = Bar(a=10, b="20")


foo.update(bar)  # error
foo.update({"a": 10, "b": "20"})  # no error

VS Code extension or command-line

pyright 1.1.333

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intendedbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions