Make einfo compatible with inspect (fixes #176)#392
Conversation
auvipy
left a comment
There was a problem hiding this comment.
please check the test failures in the CI
|
we will need to fix the CI first |
There was a problem hiding this comment.
Pull request overview
This PR makes the custom traceback, frame, and code classes in billiard compatible with Python's inspect module by overriding the __class__ property to return the corresponding native types. This fixes issue #176 where libraries like Sentry and better-exceptions fail when trying to use inspect.getinnerframes() and similar functions on billiard's custom traceback objects.
Changes:
- Added
__class__property overrides to_Code,_Frame,_Truncated, andTracebackclasses to return their correspondingtypesmodule counterparts - Added comprehensive test suite for inspect module compatibility, including tests for
istraceback,isframe,iscode,getframeinfo, andgetinnerframes - Added helper function
make_python_tb()to create test traceback objects
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| billiard/einfo.py | Added __class__ property overrides to _Code, _Frame, _Truncated, and Traceback classes to make them compatible with isinstance checks in the inspect module |
| t/unit/test_einfo.py | Added new test class test_inspect with tests for inspect module functions, and added helper function make_python_tb() to generate test tracebacks |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ffa6894 to
ad49b56
Compare
cdc1f67 to
0f8275a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
thanks for fixing the CI. and please do not force push for easier review and diff. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Libraries like
sentryorbetter-exceptionswill fail while traversing exception chains withgetframeinfolike this:As mentioned in #176, we can not inherit from
types.Tracebackand friends, but it's possible to override__class__which will make theisinstancecheck pass. This is also used internally by Python'sunittest.mockmodule.An alternative approach could be to use a meta class and implement
__subclasscheck__1, but that felt too involved.Footnotes
https://docs.python.org/3/reference/datamodel.html#class.__subclasscheck__ ↩