microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.71k stars 765 forks source link

[language-server]: only one suggestion for TypedDict union literal values #6559

Open RobertCraigie opened 1 week ago

RobertCraigie commented 1 week ago

Describe the bug

Pyright will only suggest one Literal value for a TypedDict union:

Image

Ideally it'd suggest both a and b.

Code or Screenshots

from __future__ import annotations

from typing import Union
from typing_extensions import Literal, TypedDict

class EventA(TypedDict):
    type: Literal["a"]

class EventB(TypedDict):
    type: Literal["b"]

Event = Union[EventA, EventB]

event: Event = {"type": ""}

VS Code extension or command-line

pyright language server: v1.1.384

erictraut commented 1 week ago

Since this is a language server feature, it's the domain of pylance rather than pyright.

Could someone from the pylance team please transfer this issue and prioritize it as you see fit? Thanks!