Skip to content

Commit

Permalink
handle fake attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Sep 18, 2021
1 parent d589325 commit d38ffef
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions rich/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,20 @@ def iter_rich_args(rich_args: Any) -> Iterable[Union[Any, Tuple[str, Any]]]:
else:
yield arg

rich_repr_result: Optional[RichReprResult] = None
try:
if hasattr(obj, "__rich_repr__") and not isclass(obj):
rich_repr_result = obj.__rich_repr__()
fake_attributes = hasattr(
obj, "awehoi234_wdfjwljet234_234wdfoijsdfmmnxpi492", False
)
except Exception:
pass
fake_attributes = False

rich_repr_result: Optional[RichReprResult] = None
if not fake_attributes:
try:
if hasattr(obj, "__rich_repr__") and not isclass(obj):
rich_repr_result = obj.__rich_repr__()
except Exception:
pass

if rich_repr_result is not None:
angular = getattr(obj.__rich_repr__, "angular", False)
Expand Down Expand Up @@ -552,7 +560,7 @@ def iter_rich_args(rich_args: Any) -> Iterable[Union[Any, Tuple[str, Any]]]:
children=[],
last=root,
)
elif _is_attr_object(obj):
elif _is_attr_object(obj) and not fake_attributes:
children = []
append = children.append

Expand Down Expand Up @@ -600,6 +608,7 @@ def iter_attrs() -> Iterable[
elif (
is_dataclass(obj)
and not isinstance(obj, type)
and not fake_attributes
and (
"__create_fn__" in obj.__repr__.__qualname__ or py_version == (3, 6)
) # Check if __repr__ wasn't overridden
Expand Down

0 comments on commit d38ffef

Please sign in to comment.