Skip to content

Conversation

@SebastianSpeitel
Copy link

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate (see note about typos above).
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

I discovered, that an object with an unusual __qualname__ attribute (not a str, e.g. a descriptor) causes inspect to fail.
This can happen if an object is created this way intentionally, but I discovered it, when decorating a class with @functools.lru_cache which forwards the underlying attributes using a descriptor when it can't add the to it's __dict__ because the class uses __slots__:

from functools import lru_cache
from rich import inspect


@lru_cache
class Klaas:
    __slots__ = ("__qualname__",)


if __name__ == "__main__":
    from rich.traceback import install

    install()

    inspect(Klaas.__qualname__)
    inspect(Klaas, all=True)

I fixed it by checking the type of __qualname__ falling back to __name__ and if that isn't a str using the already provided fallback.

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.

1 participant