def __eq__(self, other) : if ObjectHelper.isNone(other) : return self is None isEqual = True for value, name in ReflectionHelper.getAttributeDataList(other) : attributeIsEqual = ReflectionHelper.getAttributeOrMethod(self, name) == ReflectionHelper.getAttributeOrMethod(other, name) isEqual = isEqual == attributeIsEqual and True == attributeIsEqual return isEqual
def __init__(self, *args, **kwargs): originalClassAttributeValueList = ReflectionHelper.getAttributeNameList( OuterEnum) if instanceLog: log.prettyPython(OuterEnum, 'originalClassAttributeValueList', originalClassAttributeValueList) OuterEnum.__init__(self, *args, **kwargs) self.__associateReturnsTo__ = associateReturnsTo attributeDataList = ReflectionHelper.getAttributeDataList(self) if instanceLog: log.prettyPython(OuterEnum, 'attributeDataList', attributeDataList) for attribute, enumValue in attributeDataList: if enumValue not in ENUM_STATIC_METHOD_NAME_LIST and enumValue not in originalClassAttributeValueList: __raiseBadImplementation__(enumValue, enum=self) nativeClassDataList = [] attributeAttributeDataList = ReflectionHelper.getAttributeDataList( attribute) if instanceLog: log.prettyPython(OuterEnum, 'attributeAttributeDataList', attributeAttributeDataList) # print(f'type({attribute}): {type(attribute)}') association = ReflectionHelper.getAttributeOrMethod( attribute, self.__associateReturnsTo__, muteLogs=True) if type(association) is type(None): # print('type(association) is type(None)') ReflectionHelper.setAttributeOrMethod( attribute, ENUM_VALUE_AS_STRING_KEY, ENUM_ITEM_CLASS_DICTIONARY.get( type(enumValue))(enumValue)) nativeClassDataList = ReflectionHelper.getAttributeDataList( type(enumValue)()) # print(f'type({enumValue}): {type(enumValue)}, type({type(enumValue)}()): {type(type(enumValue)())}') else: # print('not type(association) is type(None)') ReflectionHelper.setAttributeOrMethod( attribute, ENUM_VALUE_AS_STRING_KEY, ENUM_ITEM_CLASS_DICTIONARY.get( type(association))(association)) nativeClassDataList = ReflectionHelper.getAttributeDataList( type(association)()) # print(f'type({association}): {type(association)}, type({type(association)}()): {type(type(association)())}') # print() attribute.enumValue.enumName = enumValue ReflectionHelper.setAttributeOrMethod( attribute, ENUM_NAME_AS_STRING_KEY, enumValue) if isinstance(attribute, EnumItem): # print(attribute, attribute.enumName, attribute) updateEnumItem( attribute, attribute.enumName, attribute) ###- so that __eq__ does not crash if not c.TYPE_FUNCTION == ReflectionHelper.getClassName( attribute): attribute.enumValue.__enumItemMap__ = attribute.__enumItemMap__ attribute.enumValue.__enumItemEqMap__ = attribute.__enumItemEqMap__ for dataInstance, dataName in attributeAttributeDataList: nativeData = False for _, name in nativeClassDataList: if dataName == name: nativeData = True break if not nativeData: ReflectionHelper.setAttributeOrMethod( attribute.enumValue, dataName, dataInstance) ReflectionHelper.setAttributeOrMethod( attribute.enumValue, ENUM_VALUE_AS_STRING_KEY, ReflectionHelper.getAttributeOrMethod( attribute, self.__associateReturnsTo__, muteLogs=True)) ReflectionHelper.setAttributeOrMethod( attribute.enumValue, ENUM_NAME_AS_STRING_KEY, enumValue) ReflectionHelper.setAttributeOrMethod( attribute.enumValue, ENUM_AS_STRING_KEY, self) if ObjectHelper.isEmpty(OuterEnum.__enumEqList__): for attribute, value in attributeDataList: # print(f'type({value}): {type(value)}') # print(f'type({attribute}): {type(attribute)}') valueAsString = str(attribute.enumValue) if valueAsString not in ENUM_STATIC_METHOD_NAME_LIST: if valueAsString not in self.__enumMap__: self.__enumMap__[ valueAsString] = attribute.enumValue ###- ReflectionHelper.getAttributeOrMethod(attribute, valueAsString, muteLogs=True) ###- attribute else: __raiseBadImplementation__(valueAsString, enum=self) if value not in self.__enumMap__: self.__enumMap__[value] = attribute elif not self.__enumMap__[value] == attribute: __raiseBadImplementation__(valueAsString, enum=self) self.__enumEqList__.append( f'{value}({self.__associateReturnsTo__}:{valueAsString})' )