# Pastebin LDlP3VmS class FrozenEnum(EnumMeta): "prevent creation of new attributes" def __getattr__(self, name): if name not in self._member_map_: raise AttributeError('%s %r has no attribute %r' % (self.__class__.__name__, self.__name__, name)) # mypy does not know this is a metaclass and that __getattr__ is # defined in the superclass of the class that uses this # so we need to ignore the type error here. return super().__getattr__(name) # type: ignore def __setattr__(self, name, value): if name in self.__dict__ or name in self._member_map_: return super().__setattr__(name, value) raise AttributeError('%s %r has no attribute %r' % (self.__class__.__name__, self.__name__, name)) class IronicEnum(StrEnum, metaclass=FrozenEnum): @classmethod def list(cls): return list(cls.__members__)