From b67fd39eb586430a6f80de2ef2ac1960fe29ba51 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 8 Mar 2022 13:10:02 +0000 Subject: [PATCH 1/2] Handle case inspect fails on repl-defined objects --- rich/_inspect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rich/_inspect.py b/rich/_inspect.py index b3652bfb..01713e57 100644 --- a/rich/_inspect.py +++ b/rich/_inspect.py @@ -98,7 +98,8 @@ class Inspect(JupyterMixin): source_filename: Optional[str] = None try: source_filename = getfile(obj) - except TypeError: + except (OSError, TypeError): + # OSError is raised if obj has no source file, e.g. when defined in REPL. pass callable_name = Text(name, style="inspect.callable") From 38aa939341484a4b6a782157724bb5a720a0956f Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 8 Mar 2022 13:24:11 +0000 Subject: [PATCH 2/2] Add note to CHANGELOG about fix for inspecting REPL defined objects --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb6b6262..dcd9cbda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed Pretty measure not respecting expand_all https://github.com/Textualize/rich/issues/1998 - Collapsed definitions for single-character spinners, to save memory and reduce import time. - Fix print_json indent type in __init__.py +- Fix error when inspecting object defined in REPL https://github.com/Textualize/rich/pull/2037 ### Changed