Skip to content

ENH: Restore TypeError cleanup in array function dispatching#23659

Merged
charris merged 4 commits into
numpy:mainfrom
seberg:issue-23029
May 16, 2023
Merged

ENH: Restore TypeError cleanup in array function dispatching#23659
charris merged 4 commits into
numpy:mainfrom
seberg:issue-23029

Conversation

@seberg

@seberg seberg commented Apr 25, 2023

Copy link
Copy Markdown
Member

When the dispatcher raises a TypeError and it starts with the dispatchers name (or actually qualname not that it normally matters), then it is nicer for users if we just raise a new error with the public symbol name.

Python does not seem to normalize exception and goes down the unicode path, but I assume that e.g. PyPy may not do that. And there might be other weirder reason why we go down the full path. I have manually tested it by forcing Normalization.

Closes gh-23029

When the dispathcer raises a TypeError and it starts with the dispatchers
name (or actually __qualname__ not that it normally matters), then it is
nicer for users if we just raise a new error with the public symbol name.

Python does not seem to normalize exception and goes down the unicode path,
but I assume that e.g. PyPy may not do that.  And there might be other
weirder reason why we go down the full path.  I have manually tested it
by forcing Normalization.

Closes numpygh-23029
if (message == NULL) {
goto restore_error;
}
PyErr_SetObject(PyExc_TypeError, message);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to the original error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message was mutated, the original error/traceback is assumed to be irrelevant (i.e. something like TypeError: _median() doesn't have a keyword argument '...' when it should be median().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably confused here, but isn't the original error still there and this sets a new error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyErr_Fetch clears the original error. Although I think PyErr_SetObject would do so also if the error was still in progress.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyErr_Fetch clears the original error.

Ah, that is what I was missing.

@charris

charris commented May 15, 2023

Copy link
Copy Markdown
Member

The reference counting here is a tangle :)

@charris charris merged commit 6a4abb0 into numpy:main May 16, 2023
@charris

charris commented May 16, 2023

Copy link
Copy Markdown
Member

Thanks Sebastian.

@seberg seberg deleted the issue-23029 branch May 16, 2023 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: array-function wrapped functions use dispatcher name in traceback (currently)

2 participants