r"""Get a safe repr of an object for assertion error messages. The assertion formatting (util.format_explanation()) requires newlines to be escaped since they are a special character for it. Normally assertion.util.format_explanation() does this but for a custom repr it is possible
(obj: object)
| 427 | |
| 428 | |
| 429 | def _saferepr(obj: object) -> str: |
| 430 | r"""Get a safe repr of an object for assertion error messages. |
| 431 | |
| 432 | The assertion formatting (util.format_explanation()) requires |
| 433 | newlines to be escaped since they are a special character for it. |
| 434 | Normally assertion.util.format_explanation() does this but for a |
| 435 | custom repr it is possible to contain one of the special escape |
| 436 | sequences, especially '\n{' and '\n}' are likely to be present in |
| 437 | JSON reprs. |
| 438 | """ |
| 439 | maxsize = _get_maxsize_for_saferepr(util._config) |
| 440 | return saferepr(obj, maxsize=maxsize).replace("\n", "\\n") |
| 441 | |
| 442 | |
| 443 | def _get_maxsize_for_saferepr(config: Optional[Config]) -> Optional[int]: |
nothing calls this directly
no test coverage detected