f | class ExceptionTree: | f | class ExceptionTree: |
| | | |
| def __init__(self): | | def __init__(self): |
n | self.classes = {} | n | self._cache = {} |
| | | |
n | def __call__(self, n): | n | def __call__(self, index): |
| if n not in self.classes: | | if index not in self._cache: |
| if n == 1: | | if index == 1: |
| base = Exception | | base_exception = Exception |
| else: | | else: |
t | parent_index = n // 2 | t | parent_index = index // 2 |
| base = self(parent_index) | | base_exception = self(parent_index) |
| new_class = type(f'Exception{n}', (base,), {'n': n}) | | exception_class = type(f'Exception{index}', (base_exception, |
| | | ), {'n': index}) |
| self.classes[n] = new_class | | self._cache[index] = exception_class |
| return self.classes[n] | | return self._cache[index] |