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