diff --git a/rich/pretty.py b/rich/pretty.py index 5c725c0c5..926e02415 100644 --- a/rich/pretty.py +++ b/rich/pretty.py @@ -1,5 +1,6 @@ import builtins import collections +import pathlib import dataclasses import inspect import os @@ -816,6 +817,12 @@ def iter_attrs() -> ( child_node.key_separator = "=" append(child_node) pop_visited(obj_id) + + # START of new code block + elif isinstance(obj, pathlib.Path): + node = Node(value_repr=repr(str(obj))) + # END of new code block + elif _safe_isinstance(obj, _CONTAINERS): for container_type in _CONTAINERS: if _safe_isinstance(obj, container_type): diff --git a/test_my_fix.py b/test_my_fix.py new file mode 100644 index 000000000..76e5d3ddc --- /dev/null +++ b/test_my_fix.py @@ -0,0 +1,11 @@ +# test_my_fix.py +import pathlib +from rich.pretty import pprint + +# Create a Path object to test +my_file_path = pathlib.Path("./my_folder/my_script.py") + +# This will use the code you just modified! +print("--- Running test with the fix ---") +pprint(my_file_path) +print("-------------------------------") \ No newline at end of file