Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upChain exceptions where appropriate #15986
Comments
Sure @JanukanS, thanks. We don't usually assign issues. So you can search for these type of calls and simply open a PR with suggested changes linking this issue. |
Hi @seberg |
This solution is related to the issue #15986. I also made a change to the newer string formatting. Uses NameError, which prints nicer, and is actually the more correct error type. Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
This solution is related to the issue numpy#15986. I also made a change to the newer string formatting. Uses NameError, which prints nicer, and is actually the more correct error type. Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Can I work on this issue? It is my first issue and I want to give it a try! |
this solution is related to the following issue #15986 Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
@ayao451 please feel free. A good place to start might be by checking the PRs linked in this issue: exception chaining has been added in quite a few places, and a few other instances have been identified as better off unchanged (e.g. nested exceptions in the test suite). |
A lot of these instances have been fixed (thanks to all the contributors for this!) It would be nice to have a "definition of done" for this issue if anyone wants to do a little forensics to see what's already been tackled, what's been reviewed and determined better left as-is, and what still remains to be done. |
@rossbar I think I can help the 'forensics' you describe above. My thought was to create a regex expression to search for instances of nested exceptions in the codebase (excluding tests). Something like Then I could cross-reference that list with those instances that have already been addressed in the PRs above, and make a table of what's been addressed and what still needs to be reviewed. Does that seem like a reasonable approach? I'm a complete beginner, found this issue through the 'good first issue' tag, so just want to ensure I'm not going down a rabbit hole or creating additional confusion. |
@nkleinbaer that approach sounds reasonable, and I think tabulating the results in this issue would be very useful. Even if the cross-referencing proves to be difficult to automate, having a list of all of the potential instances for exception chaining would help finish off this issue. If you are interested in taking this on I think that'd be great! Feel free ping with any questions/comments. |
OK, to start off here is a table of the files that have been touched in reference to this issue, the number of instances reviewed, the action taken, and associated PRs. I've used the nomenclature "Implemented exception chaining" to indicate something of the form In some cases my regex found additional instances of 'nested' exceptions in these files that I do not see included in the PRs. It may be the case that they were intentionally left as is, but because I cannot find any documented 'review' of them I have included them for completeness.
|
And here is a table of additional files/instances found by my regex that have NOT yet been reviewed in a PR related to this issue. Some of these look like they are already handling exception chaining properly (example einsumfunc.py), but again included here for completeness because I see no documentation of an explicit review. |
Thanks for taking the time to put this report together @nkleinbaer , this is a really nice review of the current state of things! I think the most effective way to present the information to help close this issue would be if we could take all of the instances that you found in your regex search, and list them using a list of checkboxes, e.g.
where instances that have been changed or reviewed get a check, and instances that haven't been addressed yet are left un-checked. That way, we have a running list of the instances where a decision has been made (whether to chain exceptions, use This should give us a list like: which I believe GitHub will summarize in a progress bar for the issue. If it is easy for you to re-organize your results in this way and you don't mind the extra effort, it'd be great if you could add a list formatted as described in a comment below, then I will take the list and move it up to the top comment so it is more visible. You've already done plenty though, so if you don't have the bandwidth that's totally fine - just let me know and I'll organize the list using your results. Thanks for all you've done so far! |
Sure, I can do that! I actually wanted to have check boxes in the tables above, but couldn't figure out how to do the formatting (not sure if possible at all). Mega-checklist to follow. |
@nkleinbaer I wasn't able to add the full list to the top comment (trying to do so gave github fits), so I've linked to it instead. Many thanks for compiling it! |
Hi, picked this file numpy/numpy/lib/arraypad.py to update exceptions and created a pull request. |
I found more: #17108. |
This edit is relation to issue gh-15986. Chained exception in shape_base.py
In the recent developer meeting we discussed this issue, which is pretty low on the benefit/cost ratio. We would like to suggest that contributors show the output from the error. This will require you think about the error: is the code path actually hit? Does it make sense to chain the exception? |
Picking up from #15731, there are many places in numpy where we do something like:
It would produce a marginally clearer error if we could change these to use traceback chaining. Our two options are either:
from e
.from None
:An example of such a change would be this line of this otherwise-discarded patch.
For now, I would recommend we only apply this to cases where the exception is thrown unconditionally, as other cases can be more nuanced.
Please see this list for potential places to contribute. Special thanks to @nkleinbaer for compiling the list!