Skip to content

Make einfo compatible with inspect (fixes #176)#392

Merged
auvipy merged 3 commits intocelery:mainfrom
mrcljx:patch-inspect
Feb 2, 2026
Merged

Make einfo compatible with inspect (fixes #176)#392
auvipy merged 3 commits intocelery:mainfrom
mrcljx:patch-inspect

Conversation

@mrcljx
Copy link
Contributor

@mrcljx mrcljx commented Aug 2, 2023

Libraries like sentry or better-exceptions will fail while traversing exception chains with getframeinfo like this:

AttributeError: 'Traceback' object has no attribute 'f_lineno'

As mentioned in #176, we can not inherit from types.Traceback and friends, but it's possible to override __class__ which will make the isinstance check pass. This is also used internally by Python's unittest.mock module.

    @property
    def __class__(self):
        if self._spec_class is None:
            return type(self)
        return self._spec_class

An alternative approach could be to use a meta class and implement __subclasscheck__ 1, but that felt too involved.

Footnotes

  1. https://docs.python.org/3/reference/datamodel.html#class.__subclasscheck__

@auvipy auvipy self-requested a review August 2, 2023 15:21
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check the test failures in the CI

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please rebase?

@auvipy
Copy link
Member

auvipy commented Jan 27, 2026

we will need to fix the CI first

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and Traceback classes to return their corresponding types module counterparts
  • Added comprehensive test suite for inspect module compatibility, including tests for istraceback, isframe, iscode, getframeinfo, and getinnerframes
  • 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.

@mrcljx mrcljx force-pushed the patch-inspect branch 2 times, most recently from ffa6894 to ad49b56 Compare January 27, 2026 10:57
@mrcljx mrcljx requested a review from auvipy January 27, 2026 10:59
@mrcljx mrcljx force-pushed the patch-inspect branch 2 times, most recently from cdc1f67 to 0f8275a Compare January 30, 2026 17:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@auvipy
Copy link
Member

auvipy commented Feb 1, 2026

thanks for fixing the CI. and please do not force push for easier review and diff.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@auvipy auvipy merged commit 7825a7d into celery:main Feb 2, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants