Skip to content

dict[str, str] is not assignable to TypedDict key... [bad-typed-dict-key] #3122

@lolpack

Description

@lolpack

Pyrefly infers that a dict is a typed dict and gives a confusing error as result. The root cause of this error is that we do not union an unknown value in a dict. pyright, mypy and ty all widen the value to include the union of unknown/Any whereas Pyrefly does not.

At a minimum this error should be a bad assignment or argument error like pyright mypy ty. But we probably should just allow the union and put the stricter behavior behind a flag.

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEArugNbq4Du6dENxulAFzoBVFm04AddFJrw0Acxh0AvHWBS6muhJCYYANwgBjGAH0ImHYm26DxmAFoLOgDQatOvYZOmATFZExDml0AF8pKUoDGFQoUwFSYhgAClk4BRgASgj0NIyAbR1UAQFUIwALWXQBHQBdFTUdHlRFAJ0BcoYabAcGSigdcPQQFxAyKLAoUkIBWigKAGI6AAVSCam6NCw8fDojXHRIeT7iiAPCKSWAZRglcpLiOEQAemfxmEnp-nlnmHRnzC4IxwZ77Q4QY6UU4HZ50MD8OiofSoaCobCwPYHI4nARnLi4Yi4g5wC7oMgdA4OfQwShwPENHQAZkIAEZ-CApBBDjSHOwIB0HJBaQJenAYMowLExVJ8jTqLTalImDw%2BIIYJgHJgIFEjLjqQ0AOQQthRA1SNgiqIARwY2vVDmYMFIDjKJnShvYqEo6DNw1CozKepgADFoDAKFscAQSORQkA

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.typecheckingusabilityUsability & readiness issues identified with running Pyrefly on top OSS projects

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions