f | class NegExt: | f | class NegExt: |
| | | |
| def __neg__(self): | | def __neg__(self): |
n | cls = self.__class__ | n | class_reference = self.__class__ |
| for base in cls.__mro__[1:]: | | for ancestor in class_reference.__mro__[1:]: |
| if hasattr(base, '__neg__') and callable(base.__neg__) and ( | | if hasattr(ancestor, '__neg__') and callable(ancestor.__neg_ |
| base is not NegExt): | | _) and (ancestor is not NegExt): |
| try: | | try: |
n | result = base.__neg__(self) | n | neg_result = ancestor.__neg__(self) |
| return cls(result) | | return class_reference(neg_result) |
| except TypeError: | | except TypeError: |
| continue | | continue |
| if hasattr(self, '__getitem__'): | | if hasattr(self, '__getitem__'): |
| try: | | try: |
n | sliced = self[1:-1] | n | sliced_part = self[1:-1] |
| return cls(sliced) if not isinstance(self, dict) else cl | | return class_reference(sliced_part) if not isinstance(se |
| s(sliced.items()) | | lf, dict) else class_reference(sliced_part.items()) |
| except (TypeError, IndexError, KeyError): | | except (TypeError, IndexError, KeyError): |
| pass | | pass |
t | return cls(self) if not isinstance(self, dict) else cls(self.ite | t | return class_reference(self) if not isinstance(self, dict) else |
| ms()) | | class_reference(self.items()) |