Keep debug() working when an object's repr raises

AK
3h ago
+18-1

When pretty printing raises, debug() falls back to calling repr() on the value. If that also raises (for example, a repr that accesses a closed resource), the debugging call currently raises instead of returning the original object.

Keep the normal repr fallback. If it raises, print <unrepresentable value> with the type and the original pretty-printing diagnostic, then return the original object as usual.

Validation: The focused regression failed before and passed after the change. The full pytest suite passed (154 passed, 1 skipped). Ruff lint and formatting checks and strict basedpyright passed.

Prepared and tested with AI assistance.


Summary by cubic

debug() no longer raises when both pretty printing and repr() fail. It prints <unrepresentable value> with the object's type and the pretty-printing diagnostic, then returns the original object as before. Added a regression test for a value whose repr raises.