Hello,
Consider the following:
from enum import Enum
class MyEnum(Enum):
x = "x"
y: 'MyEnum' = "y"
z = "z" # type: 'MyEnum'
def accept_str(s: str): pass
accept_str("hello") # OK, as expected
accept_str(MyEnum.x.value) # OK, as expected
accept_str(MyEnum.x) # Not OK, but pytype is silent
accept_str(MyEnum.y) # Not OK, but pytype is silent
accept_str(MyEnum.z) # Not OK, but pytype is silent
Pytype finds nothing to complain about when MyEnum.x is of <enum MyEnum> type, and not str (which is the case for MyEnum.x.value).
Also for IntEnums:
from enum import IntEnum
class MyIntEnum(IntEnum):
a = 1
b: 'MyIntEnum' = 2
c = 3 # type: 'MyIntEnum'
def accept_int(i: int): pass
accept_int(42) # OK, as expected
accept_int(MyIntEnum.a.value) # OK, as expected
accept_int(MyIntEnum.a) # Not OK, but pytype is silent
accept_int(MyIntEnum.b) # Not OK, but pytype is silent
accept_int(MyIntEnum.c) # Not OK, but pytype is silent
pytype version: 2020.05.13
Reactions are currently unavailable
Hello,
Consider the following:
Pytype finds nothing to complain about when MyEnum.x is of <enum MyEnum> type, and not str (which is the case for MyEnum.x.value).
Also for IntEnums:
pytype version: 2020.05.13