Call PyErr_NormalizeException for exceptions#1265
Call PyErr_NormalizeException for exceptions#1265lostmsu merged 17 commits intopythonnet:masterfrom slide:normalize_exceptions
Conversation
|
@slide tbh, I think it would be better to be fixed by checking if I am not sure if the
|
|
This function is called in PyErr_Print, which is why I thought it would be safe. Would you rather the call be moved to the Format method itself? |
|
Can you clarify on behavior of A test for scenario 1 is still required (e.g. when exception class has |
Codecov Report
@@ Coverage Diff @@
## master #1265 +/- ##
=======================================
Coverage 87.97% 87.97%
=======================================
Files 1 1
Lines 291 291
=======================================
Hits 256 256
Misses 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
|
The reference count stuff is something I tend to struggle with in regards to C# vs. Python stuff. :-) From looking at the source it looks like things would only be DECREF'd in case of an error or if the value is updated to be the correct value (https://github.com/python/cpython/blob/98c4433a81a4cd88c7438adbee1f2aa486188ca3/Python/errors.c#L353 and https://github.com/python/cpython/blob/98c4433a81a4cd88c7438adbee1f2aa486188ca3/Python/errors.c#L336). In the case of an error, it looks like PyErr_NormalizeException will chain the new exception and try and normalize it. https://github.com/python/cpython/blob/98c4433a81a4cd88c7438adbee1f2aa486188ca3/Python/errors.c#L366. So, it seems like case 1 is covered internally in the normalization process. I can add something though just to make sure. |
|
From my reading the code you linked, it looks like you need to incref pointers before sending them to For example, they decref |
|
I have NOT abandoned this PR, just had some work stuff come up. I will revisit for item 1 above shortly. |
|
I ran the same code on C Python 3.7.7 interpreter and got this, so the behavior matches: |
|
@slide I don't think the new test with |
|
You're absolutely right, I was thinking of something else, this makes complete sense. |
…o normalize_exceptions
|
closing and reopening to get a new build |
|
Thanks! |
See https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NormalizeException
What does this implement/fix? Explain your changes.
This fixes cases where some exceptions are "unnormalized" (see https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NormalizeException). Calling PyErr_NormalizeException will normalize the exception so that any calls to the traceback module functions correctly.
Does this close any currently open issues?
#1190
Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG