I would like to extend Python Enums to support non-defined values.
My use case: I want to benefit from Enums (e.g., being able to address/compare known entries with speaking names) but I also want it to support unknown values. If there's no name behind the value, str should simply print the str representation of the value and comparisons should fail.
Let me give you a short example what I'd like to have:
from enum import Enum
class Foo(Enum):
A = 1
B = 2
C = 3
def __str__(self):
return self.name
print(Foo(1)) # prints 'A'
print(Foo(2)) # print 'B'
print(Foo(3)) # prints 'C'
print(Foo(1) == Foo.A) # prints 'true'
print(Foo(4)) # I'd expect '4'
print(Foo(123)) # I'd expect '123'
print(Foo(123) == Foo.A) # I'd expect False
Of course the last lines fail.
Is there a way to extend Enums, or is there maybe another easy pythonic way? (No third party libraries, please.)