Consider the following code, if you will:
class ParentService:
BASE_DIR = '/some/path'
class Results(str, Enum):
RESULT1 = 'ResultOne.xlsx'
RESULT2 = 'ResultTwo.pdf'
def file_path(self) -> str:
return os.path.join(self.BASE_DIR, self.value)
class ParentException(Exception):
def __init__(self, result_type: Results): # Unresolved reference 'Results'
self.result_type = result_type
self.msg = f'There is a problem with {result_type}'
super().__init__(self.msg)
@classmethod
def file_exists(cls, file: Results):
if not os.path.exists(file.file_path()):
raise self.ParentException(result_type=file)
Is it possible – and if it is, what is the correct way – to access the Results
inner class Enum in the ParentException
initialiser for the purposes of limiting the result_type
parameter options?
Thanks!