Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Python3.14 compatibility https://github.com/Textualize/rich/pull/3861

### Fixed

- Fixed exception when callling `inspect` on objects with unusual `__qualname__` attribute https://github.com/Textualize/rich/pull/3894

## [14.1.0] - 2025-06-25

### Changed
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ The following people have contributed to the development of Rich:
- [Jonathan Helmus](https://github.com/jjhelmus)
- [Brandon Capener](https://github.com/bcapener)
- [Alex Zheng](https://github.com/alexzheng111)
- [Sebastian Speitel](https://github.com/SebastianSpeitel)
4 changes: 4 additions & 0 deletions rich/_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def _get_signature(self, name: str, obj: Any) -> Optional[Text]:
signature_text = self.highlighter(_signature)

qualname = name or getattr(obj, "__qualname__", name)
if not isinstance(qualname, str):
qualname = getattr(obj, "__name__", name)
if not isinstance(qualname, str):
qualname = name

# If obj is a module, there may be classes (which are callable) to display
if inspect.isclass(obj):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ class Thing:
assert render(module, methods=True) == expected


def test_qualname_in_slots():
from functools import lru_cache

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

try:
inspect(Klass)
except Exception as e:
assert False, f"Class with __qualname__ in __slots__ shouldn't raise {e}"


@pytest.mark.parametrize(
"special_character,expected_replacement",
(
Expand Down