Skip to content

Mypy doesn't assign TypedDict output as Literals #16534

Open
@tygoee

Description

@tygoee

Bug Report

(A clear and concise description of what the bug is.)

To Reproduce

When I do this, I get an error saying a literal is required. When I add a literal it can't assign a string to a literal.

Actual Behavior

When using the first way, I got this error:

main.py:19: error: TypedDict key must be a string literal; expected one of ("b", "c", "d")  [literal-required]
Found 1 error in 1 file (checked 1 source file)

The second way this one:

main.py:19: error: Incompatible types in assignment (expression has type "str", variable has type "Literal['b', 'c', 'd']")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Your Environment

I used the standard strict configuration from vscode, I don't know where I could find the version info and default command-line flags.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions