from typing import List, TypeVar, Type,cast T=TypeVar("T",bound=Type) def enumValues(claz:T)->List[T]: ''' @param claz the class of which the enum values are needed @returns the enum values in given clazz T. Assumption : T contains some objects of type T and these are the enum values of T. ''' values:List[T] = [getattr(claz, nm) for nm in dir(claz)] return [val for val in values if isinstance(val, claz)] def enumToString(item:T) -> str: ''' @param an enum element. @return a string S containing the name of this element. S is such that getattr(item, S) = item. Assumption : enum types T contain some objects of type T and these are the enum values of T. ''' return [name for name in dir(type(item)) if getattr(type(item), name)==item][0] class enum: def __repr__(self)->str: return enumToString(self) #type:ignore