-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: Ensure dispatcher TypeErrors report original name #21731
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
Conversation
Does this add any measureable slowdown in the case where there is no error? |
This replaces the name in the TypeError with the actually raised name. In principle we could add one more check, because a signature related TypeError must have a traceback with exactly one entry (so `sys.exc_info()[2].tb_next is None`). In practice this seems unnecessary though. This ensures the following message: >>> np.histogram(asdf=3) TypeError: histogram() got an unexpected keyword argument 'asdf' Closes numpygh-21647
7079865
to
8fabdec
Compare
Hmmm, the benchmarks give something like:
(not super reliable on these time scalas, but that is the rough idea I guess) So it is measurable on the cheapest functions (those functions are as cheap as it gets). |
Well, not sure if its worth it, I don't like the weird name, of course completely incorrect signatures are maybe not super common. The question is really whether this confuses new users or not (and I have no idea). |
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.
Looks very good to me! Happy that it was not too much work.
Personally I would lean against this solution -- I'm not sure the slight overhead in every NumPy function call is worth it. |
Note that in newest python (3.11) there is no overhead whatsoever for a |
I'm OK with this, especially if the try..except is as fast as claimed in Python 3.11
|
agreed! |
Let's put this in, then. Thanks Sebastian. |
This replaces the name in the TypeError with the actually raised
name. In principle we could add one more check, because a
signature related TypeError must have a traceback with exactly
one entry (so
sys.exc_info()[2].tb_next is None
).In practice this seems unnecessary though.
This ensures the following message:
Closes gh-21647