Skip to content

Recognize list of constant values as a list of str. #13767

@elda27

Description

@elda27

Feature
I wish mypy is recognized list of constant values as a list of literal types.

Pitch
There are example code.

from typing import Literal, Dict
values: Dict[Literal["from", "to", "cc"], str] = {}

# key should be recognized Literal["from","to", "cc"] instead of str
for key in ["from", "to", "cc"]: 
    values[key] = key # Now, this line will be error in order to recognize key as a str.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions