Skip to content

TypedDict doesn't support Union[Literal] as key "string literal" #7752

Open
@b0g3r

Description

@b0g3r

Possibly bug.
Related: #7644

Reproducible example

from typing_extensions import Literal, TypedDict

class TDict(TypedDict):
    KEY1: int
    KEY2: int

d1: TDict = {'KEY1': 1, 'KEY2': 2}

key2: Literal['KEY1']
d2: TDict = {key2: 1, 'KEY2': 2}

key3: Literal['KEY1', 'KEY2']
d3: TDict = {key3: 1, 'KEY2': 2}  # error: Expected TypedDict key to be string literal

I use mypy 0.740 and python3.6

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions