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
版权声明:本文标题:python - Accessing a sibling inner class in initialiser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744794894a2625518.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论