basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

enum types are not assignable to a union of all their values

Open DetachHead opened this issue 11 months ago • 1 comments

Description

Code sample in basedpyright playground

from enum import Enum
from typing import Literal


class Foo(Enum):
    a = 1
    b = 2


type FooBound = Literal[Foo.a, Foo.b]

def _(value: Foo):
    _: FooBound = value # error

this should be allowed because enums are final and can't be subtyped with additional values, therefore this is safe

DetachHead avatar Mar 31 '25 06:03 DetachHead

upstream issue: https://github.com/microsoft/pyright/issues/9185

DetachHead avatar Mar 31 '25 06:03 DetachHead