Improve Python <-> .NET exception integration#1134
Merged
lostmsu merged 42 commits intopythonnet:masterfrom Jun 1, 2021
Merged
Improve Python <-> .NET exception integration#1134lostmsu merged 42 commits intopythonnet:masterfrom
lostmsu merged 42 commits intopythonnet:masterfrom
Conversation
…ET interop New method ThrowLastAsClrException should be used everywhere instead of obsolete PythonException constructor. It automatically restores .NET exceptions, and applies codecs for Python exceptions. Traceback, PyVal and PyType are now stored and returned as PyObjects. PythonException now has InnerException set from its cause (e.g. __cause__ in Python, if any). PythonException.Restore no longer clears the exception instance. All helper methods were removed from public API surface.
…chInfo masking exception object
4fe0548 to
0961c94
Compare
The new type indicates parameters of C API functions, that steal references to passed objects.
Removed private fields, apart from ones returned by `PyErr_Fetch`. Corresponding property values are now generated on demand. Added FetchCurrent*Raw for internal consumption. `PythonException.Type` is now of type `PyType`. Use C API functions `PyException_GetCause` and `PyException_GetTraceback` instead of trying to read via attributes by name. `PythonException` instances are no longer disposable. You can still dispose `.Type`, `.Value` and `.Traceback`, but it is not recommended, as they may be shared with other instances.
Member
Author
|
Damn CI failures do not reproduce locally :/ |
- no longer leaking iterator object on failure - when iteration stops due to error, propagates the error
4c76f15 to
4877fe7
Compare
1512a55 to
87dd9fd
Compare
87dd9fd to
6679d1c
Compare
f812ec7 to
651d145
Compare
…tp_dealloc and don't override Dealloc
651d145 to
c500a39
Compare
|
Hello, given that catch (PythonException ex) when (ex.PyType == Exceptions.KeyError) |
Member
Author
|
@Felk You can get |
|
Thank you, this is how I got it to work now: dynamic builtins = Py.Import("builtins");
try
{
// ...
}
catch (PythonException ex) when (ex.Type.Equals(builtins.KeyError))
{
// ...
} |
Member
Author
|
@Felk comparing type handles will be slightly faster |
|
@lostmsu can you give me an example of what you mean? |
Member
Author
|
@Felk If you really cared, you'd also cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix? Explain your changes.
PythonExceptionwas thrown instead).InnerExceptionproperty is populated from Python's__cause__attribute.PythonExceptionclass. Instead of working with raw pointers, usesPyObjectinstances.Breaking
Traceback,PyValandPyTypeare now stored and returned asPyObjects.PythonException.Restoreno longer nulls outPythonExceptioninstance.PythonExceptioninstances are no longer disposable. You can still dispose.Type,.Valueand.Traceback, but it is not recommended, as they may be shared with other instances.Does this close any currently open issues?
#893, #1098
Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG