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