Skip to content

Inconsistent behavior with Literals depending on the amount of elements it contains #9099

Open
@ethan-leba

Description

@ethan-leba

This is an issue I ran into working on #9097.
Code adapted from this test.

Literals with one value:

from typing import List
from typing_extensions import Literal

lit1: Literal[1]
lit2: Literal[2]

arr2 = [lit1, lit2]

reveal_type(arr2)
➜  mypy git:(master) python3 -m mypy leba_misc/test2.py
leba_misc/test2.py:9: note: Revealed type is 'builtins.list[builtins.int*]'

Literals with multiple values:

from typing import List
from typing_extensions import Literal

lit1: Literal[1]
lit2: Literal[2, 3]

arr2 = [lit1, lit2]

reveal_type(arr2)
➜  mypy git:(master) python3 -m mypy leba_misc/test2.py
leba_misc/test2.py:9: note: Revealed type is 'builtins.list[Union[Literal[1], Literal[2], Literal[3]]]'

On Python 3.7 and mypy 0.790.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions