Skip to content
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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mrcljx
Copy link

@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?

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