I have a class which is derived from enum.Enum. Now repr in enum.Enum refers to the member of the enum.Enum not the entire class.
For Example
from enum import Enum
class endpoints(Enum):
""" shop """
shop = 'shop'
countries = 'countries'
policies = 'policies'
print(endpoints)
Result
<enum 'endpoints'>
What I tried
from enum import Enum
class endpoints(Enum):
shop = 'shop'
countries = 'countries'
policies = 'policies/{object_id}'
@classmethod
def __repr__(cls):
return '\n'.join([str(member.name) + ':' + (member.value) for member in cls.__members__])
print(endpoint)
Result
<enum 'endpoints'>
This indicates that repr is effectively endpoints.member.repr what I need is endpoint.repr?
I understand this can be achieved by a metaclass here, but since Enum itself has a metaclass, I cannot inherit/assign from another metaclass.
stopping short of modifying enum.Enum how can I achieve my objective.
The desired output is as follows.
print(endpoints)
shop : shop
countries : countries
policies : policies/{object_id}