Method: rich.pretty._has_default_namedtuple_repr
Calls: 10, Exceptions: 0, Paths: 1Back
Path 1: 10 calls (1.0)
test_reference_cycle_namedtuple.
True (9) False (1)
1def _has_default_namedtuple_repr(obj: object) -> bool:
2 """Check if an instance of namedtuple contains the default repr
3
4 Args:
5 obj (object): A namedtuple
6
7 Returns:
8 bool: True if the default repr is used, False if there's a custom repr.
9 """
10 obj_file = None
11 try:
12 obj_file = inspect.getfile(obj.__repr__)
13 except (OSError, TypeError):
14 # OSError handles case where object is defined in __main__ scope, e.g. REPL - no filename available.
15 # TypeError trapped defensively, in case of object without filename slips through.
16 pass
17 default_repr_file = inspect.getfile(_dummy_namedtuple.__repr__)
18 return obj_file == default_repr_file