Skip to content

Commit

Permalink
fix: str of KeyError for <3.11 (#2519)
Browse files Browse the repository at this point in the history
Co-authored-by: Jim Pivarski <[email protected]>
  • Loading branch information
agoose77 and jpivarski authored Jun 14, 2023
1 parent 1e65496 commit f81d2bf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/awkward/_errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
from __future__ import annotations

import builtins
import sys
import threading
import warnings
Expand Down Expand Up @@ -31,6 +32,11 @@ def __call__(self):
return self.func(*self.args, **self.kwargs)


class KeyError(builtins.KeyError):
def __str__(self):
return super(Exception, self).__str__()


class ErrorContext:
# Any other threads should get a completely independent _slate.
_slate = threading.local()
Expand Down Expand Up @@ -87,6 +93,9 @@ def decorate_exception(self, cls: type[E], exception: E) -> E:
+ "\n\nSee if this has been reported at https://github.com/scikit-hep/awkward/issues"
)
new_exception.__cause__ = exception
elif issubclass(cls, builtins.KeyError):
new_exception = KeyError(self.format_exception(exception))
new_exception.__cause__ = exception
else:
new_exception = cls(self.format_exception(exception))
new_exception.__cause__ = exception
Expand Down

0 comments on commit f81d2bf

Please sign in to comment.