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

refactor: AttributeError handling for sphinx.util.inspect.get* is not needed #8799

Merged
merged 4 commits into from
Feb 1, 2021

Conversation

tk0miya
Copy link
Member

@tk0miya tk0miya commented Jan 31, 2021

Feature or Bugfix

  • Refactoring

Purpose

  • Internally, getall(), getannotations(), getmro() and getslots() in sphinx.util.inspect use safe_getattr() with the default keyword. Therefore it never raises AttributeError even if the subject raises an error on accessing __mro__ attribute.
  • This fixes the wrong their usage.

Internally, sphinx.util.inspect.getmro() uses `safe_getattr()` with
the `default` keyword.  Therefore it never raises AttributeError even if
the subject raises an error on accessing `__mro__` attribute.

This fixes the wrong its usage.
@tk0miya
Copy link
Member Author

tk0miya commented Jan 31, 2021

I confirmed with sphinx.util.inspect.getannotations() suppresses errors on accessing its attribute with following code:

>>> class Foo:
...     @property
...     def __annotations__(self):
...         raise
...
>>>
>>> foo = Foo()
>>> foo.__annotations__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in __annotations__
RuntimeError: No active exception to reraise
>>> from sphinx.util import inspect
>>> inspect.getannotations(foo)
{}

@tk0miya tk0miya merged commit 7ca279e into sphinx-doc:3.x Feb 1, 2021
@tk0miya tk0miya deleted the refactor_util_get branch February 1, 2021 12:04
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant