Skip to content

TypedDict union assignment error doesn't identify the invalid tag #5771

In review

Description

@rchiodo

Describe the Bug

Repro: Save this as repro.py and run pyrefly check --preset default repro.py. I reproduced it on upstream main at 188f28cd2.

from typing import Literal, TypedDict

class Cat(TypedDict):
    kind: Literal["cat"]
    lives: int

class Dog(TypedDict):
    kind: Literal["dog"]
    bark: bool

cat: Cat | Dog = {"kind": "cat", "lives": 9}
dog: Cat | Dog = {"kind": "dog", "bark": True}
pet: Cat | Dog = {"kind": "bird", "lives": 1}

Actual: Both valid assignments pass. The third is correctly rejected, but the error only says `dict[str, int | str]` is not assignable to `Cat | Dog` [bad-assignment] and points to the whole dict.

Expected: Keep the same rejection and error kind, but explain that "bird" is invalid for kind and that the union accepts "cat" or "dog". This is a diagnostic improvement, not a change to what type-checks.

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Activity

  1. rchiodo commented on Nov 25, 2026

    @rchiodo
    CollaboratorAuthor

    #claim

  2. github-actions commented on Nov 25, 2026

    @github-actions

    @rchiodo you've claimed this issue — it's now assigned to you. Thanks for picking it up! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions