basedpyright
basedpyright copied to clipboard
enum types are not assignable to a union of all their values
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
upstream issue: https://github.com/microsoft/pyright/issues/9185