Skip to content

Treat literal of all enum members equal to type itself #11573

Description

@JoniKauf

Describe the bug
Treat Literal of all members of an enum the same way as the annotation of just that enum.

Code or Screenshots
https://discuss.python.org/t/treat-literal-of-all-elements-of-enum-equal-to-the-enum-in-type-annotations/108317
Here is the discuss.python.org link where i asked and showcased this issue. It seems to be a feature in most other type checkers already, with pyright being one of the exceptions.

Code re-pasted from there:

import enum
import typing as t

class Importance(enum.IntEnum):
    LOW = 1
    MEDIUM = 2
    HIGH = 3

type AllT = t.Literal[Importance.LOW, Importance.MEDIUM, Importance.HIGH]

class Task[T: Importance]:
    ...

def manage_task(task: Task[AllT]) -> t.Any:
    ...

task: Task[Importance] = ...

manage_task(task)  # error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions