f | class ExceptionTree: | f | class ExceptionTree: |
| | | |
| def __init__(self): | | def __init__(self): |
n | self._exceptions = {} | n | self.exceptions = {} |
| | | |
n | def __call__(self, index): | n | def __call__(self, n): |
| if index in self._exceptions: | | if n in self.exceptions: |
| return self._exceptions[index] | | return self.exceptions[n] |
| if index == 1: | | if n == 1: |
| base_exception = Exception | | par = Exception |
| else: | | else: |
t | base_exception = self(index // 2) | t | par = self(n // 2) |
| new_exception = type(f'Exception-{index}', (base_exception,), {' | | new_exc = type(f'Exception-{n}', (par,), {'n': n}) |
| n': index}) | | |
| self._exceptions[index] = new_exception | | self.exceptions[n] = new_exc |
| return new_exception | | return new_exc |