I want something like this:
class Fruits:
APPLE = 'APPLE'
ORANGE = 'ORANGE'
MANGO = 'MANGO'
# I want to access members easily
print(Fruits.APPLE)
# I want to list all members
print(list(Fruits))
# I want to check if a string belongs to the set
print('POTATO' in Fruits)
I want plain string constants, grouped into a class with:
- member check
- listing all values
Python enums do not seem to be suitable, because:
- Enums are not plain strings, introduce a new type
- Enums require using
.value - Not directly serializable and are otherwise clumsy.
Is this implementable in Python? I suppose I might need some magic methods or metaclasses for this?