f | class ExceptionTree: | f | class ExceptionTree: |
| | | |
| def __init__(self): | | def __init__(self): |
n | self.nodes = {} | n | self.exception_classes = {} |
| | | |
| def __call__(self, n): | | def __call__(self, n): |
n | if n in self.nodes: | n | if n in self.exception_classes: |
| return self.nodes[n] | | return self.exception_classes[n] |
| elif n == 1: | | if n == 1: |
| exc = type(f'E{n}', (Exception,), {'n': n}) | | exc_class = type(f'Exception-{n}', (Exception,), {'n': n}) |
| else: | | else: |
t | parent = n // 2 | t | parent_index = n // 2 |
| parent_exc = self(parent) | | parent_class = self(parent_index) |
| exc = type(f'E{n}', (parent_exc,), {'n': n}) | | exc_class = type(f'Exception-{n}', (parent_class,), {'n': n} |
| | | ) |
| self.nodes[n] = exc | | self.exception_classes[n] = exc_class |
| return exc | | return exc_class |