Get repr string for an object, but catch errors.
(obj: Any)
| 599 | """ |
| 600 | |
| 601 | def to_repr(obj: Any) -> str: |
| 602 | """Get repr string for an object, but catch errors.""" |
| 603 | if ( |
| 604 | max_string is not None |
| 605 | and _safe_isinstance(obj, (bytes, str)) |
| 606 | and len(obj) > max_string |
| 607 | ): |
| 608 | truncated = len(obj) - max_string |
| 609 | obj_repr = f"{obj[:max_string]!r}+{truncated}" |
| 610 | else: |
| 611 | try: |
| 612 | obj_repr = repr(obj) |
| 613 | except Exception as error: |
| 614 | obj_repr = f"<repr-error {str(error)!r}>" |
| 615 | return obj_repr |
| 616 | |
| 617 | visited_ids: Set[int] = set() |
| 618 | push_visited = visited_ids.add |
no test coverage detected