admin管理员组

文章数量:1404340

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!

本文标签: pythonAccessing a sibling inner class in initialiserStack Overflow