-
Notifications
You must be signed in to change notification settings - Fork 747
Improve Python <-> .NET exception integration #1134
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
…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.
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) |
@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))
{
// ...
} |
@Felk comparing type handles will be slightly faster |
@lostmsu can you give me an example of what you mean? |
@Felk If you really cared, you'd also cache |
What does this implement/fix? Explain your changes.
PythonException
was thrown instead).InnerException
property is populated from Python's__cause__
attribute.PythonException
class. Instead of working with raw pointers, usesPyObject
instances.Breaking
Traceback
,PyVal
andPyType
are now stored and returned asPyObject
s.PythonException.Restore
no longer nulls outPythonException
instance.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.Does this close any currently open issues?
#893, #1098
Checklist
Check all those that are applicable and complete.
AUTHORS
CHANGELOG