pyright icon indicating copy to clipboard operation
pyright copied to clipboard

Enum Literal Handling Regression

Open max-muoto opened this issue 9 months ago • 0 comments

To preface, apologies if there's a simpler reproducible example here, mostly trying to replicate what's happening across modules in my codebase. In Pyright 1.1.362, something like this would have been fine:


import enum
from typing import TypeAlias

class MyEnum(enum.StrEnum):
    ARG_1 = "ARG_1"
    ARG_2 = "ARG_1"
    

MyEnumAlias: TypeAlias = MyEnum

def get_enum() -> MyEnumAlias: ...

z = get_enum()

def foo(enum: MyEnum): ...

foo(z.ARG_1)

That being, we alias an enum, and pass in value off the aliased type, now in 1.1.362, you'll get a warning when trying to pass in ARG_1:

In this example, it's obviously pointless to alias, in reality, we have an enum setting that's we're aliasing to change the typing of, think, MY_ENUM as MyEnum, for a wrapper we have on some project settings.

Pyright Playground

max-muoto avatar May 15 '24 18:05 max-muoto