flake8-pyi
flake8-pyi copied to clipboard
Y011: Allow enum value defaults
For example:
def foo(x: MyEnum = MyEnum.BAR): ... # Triggers Y011 (only simple defaults)
I think enum value defaults are both simple and quite useful.
Implementation idea: If a default follows the pattern ([\w.]+)\.\w, check whether the type includes the first match group.
Implementation idea: If a default follows the pattern
([\w.]+)\.\w, check whether the type includes the first match group.
We might need something a little cleverer -- I think this regex would mean we'd still emit errors on things like
class X(enum.IntEnum):
MEMBER1 = 1
MEMBER2 = 2
def foo(x: X | int = X.MEMBER1): ...
That's what I meant by "includes". I.e. the type itself or - if it's a union - one of the union members must be equivalent to the regex group.