19Result = Iterable[Union[Any, Tuple[Any], Tuple[str, Any], Tuple[str, Any, Any]]]
38 cls: Optional[Type[T]] =
None, *, angular: Optional[bool] =
None
39) -> Union[Type[T], Callable[[Type[T]], Type[T]]]:
40 """Class decorator to create __repr__ from __rich_repr__"""
42 def do_replace(cls: Type[T], angular: Optional[bool] =
None) -> Type[T]:
44 """Create repr string from __rich_repr__"""
45 repr_str: List[str] = []
48 angular: bool =
getattr(self.__rich_repr__,
"angular",
False)
49 for arg
in self.__rich_repr__():
54 key, value, *default = arg
58 if default
and default[0] == value:
60 append(f
"{key}={value!r}")
64 return f
"<{self.__class__.__name__} {' '.join(repr_str)}>"
66 return f
"{self.__class__.__name__}({', '.join(repr_str)})"
69 """Auto generate __rich_rep__ from signature of __init__"""
83 except Exception
as error:
85 f
"Failed to auto generate __rich_repr__; {error}"
88 if not hasattr(cls,
"__rich_repr__"):
90 cls.__rich_repr__ = auto_rich_repr
93 cls.__repr__ = auto_repr
94 if angular
is not None:
95 cls.__rich_repr__.angular = angular
99 return partial(do_replace, angular=angular)