Skip to content

0.0.21 regression - invalid-assignment false positive when assigning type with invariant generic to a TypedDict key when the generic should instead be inferred as a wider type #2986

@DetachHead

Description

@DetachHead

Summary

from typing import TypedDict

class Foo:
    asdf: list[int | str]

class Bar(TypedDict):
    asdf: list[int | str]


def fn(foo: Foo, bar: Bar):
    bar["asdf"] = list([1]) # error: Invalid assignment to key "asdf" with declared type `list[int | str]` on TypedDict `Bar`: value of type `list[int]` (invalid-assignment)
    foo.asdf = list([1]) # no error, correctly inferred as list[int | str]

https://play.ty.dev/2e780e02-941e-405b-b65e-6c61a81857cf

this bug seems to have been introduced in v0.0.21

Version

0.0.21

Metadata

Metadata

Assignees

No one assigned

    Labels

    bidirectional inferenceInference of types that takes into account the context of a declared type or expected type

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions