-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Use the currently handled exception as UndefinedError.__context__ #2104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4eae184
3c1abcd
90a7e9c
89bcbb2
445e5a4
bd7526f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -813,6 +813,7 @@ class Undefined: | |
| "_undefined_obj", | ||
| "_undefined_name", | ||
| "_undefined_exception", | ||
| "_undefined_context", | ||
| ) | ||
|
|
||
| def __init__( | ||
|
|
@@ -827,6 +828,10 @@ def __init__( | |
| self._undefined_name = name | ||
| self._undefined_exception = exc | ||
|
|
||
| cause: BaseException | None | ||
| _, cause, _ = sys.exc_info() | ||
| self._undefined_context = cause | ||
|
|
||
| @property | ||
| def _undefined_message(self) -> str: | ||
| """Build a message about the undefined value based on how it was | ||
|
|
@@ -856,7 +861,10 @@ def _fail_with_undefined_error( | |
| """Raise an :exc:`UndefinedError` when operations are performed | ||
| on the undefined value. | ||
| """ | ||
| raise self._undefined_exception(self._undefined_message) | ||
| exception = self._undefined_exception(self._undefined_message) | ||
| if exception.__context__ is None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to consider
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. |
||
| exception.__context__ = self._undefined_context | ||
| raise exception | ||
|
|
||
| @internalcode | ||
| def __getattr__(self, name: str) -> t.Any: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to the issue you opened using
:issue:`...`.