Is there a way to do something like this in python?
from enum import Enum, auto
def some_func(mode = Mode.A):
class Mode(Enum):
A = auto()
print(mode == Mode.A)
desired outcome
>>> some_func()
True
The above snippet fails with NameError: name 'Mode' is not defined presumably because class Mode isn't defined when the interpreter reads def some_func(mode = Mode.A):
You can of course put the Enum outside the function but, if what I propose or something similar worked, I'd rather keep it inside. Keeping it inside encapsulates Mode where it is meant to be used, hopefully allowing . syntax to distinguish it from other similar Mode classes.
I am aware that a lot of python code just uses strings for this purpose, not bothering with Enums. However I would like to find a solution using Enums. Enums are easier to maintain and help IDEs generate code completion etc.
Is there a nice way to make this work?