mirror of
https://github.com/Textualize/rich.git
synced 2026-02-06 10:58:48 +00:00
Handle unusual __qualname__ in inspect
This commit is contained in:
parent
4d6d631a3d
commit
0c271d5bb6
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -101,6 +101,10 @@ class Inspect(JupyterMixin):
|
||||
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):
|
||||
|
||||
@ -404,6 +404,19 @@ def test_inspect_module_with_class():
|
||||
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",
|
||||
(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user