Whole file

gaogaotiantian/objprint

The author described this change as Fix printing built-in methods that miss signatures (#121). It counts as a record because the check below fails on the code as it stood at 89a9cf8b3 and passes on 297932d68, with nothing else changed between the two runs.

Fix saved2025-04-02
Sharing licenceApache-2.0 · LICENSE
Change size+8 2

What the code was meant to do, written into the code itself as a save note

Fix printing built-in methods that miss signatures (#121)

The change

220220 def _get_custom_object_str(self, obj: Any, memo: Optional[Set[int]], indent_level: int, cfg: _PrintConfig):
221221
222222 def _get_method_line(attr: str) -> str:
223+ try:
224+ method_sig = str(inspect.signature(getattr(obj, attr)))
225+ except ValueError:
226+ # Please consider special handling
227+ method_sig = "(<signature unknown>)"
228+
223229 if cfg.color:
224230 return f"{set_color('def', COLOR.MAGENTA)} "\
225- f"{set_color(attr, COLOR.GREEN)}{inspect.signature(getattr(obj, attr))}"
231+ f"{set_color(attr, COLOR.GREEN)}{method_sig}"
226232 else:
227- return f"def {attr}{inspect.signature(getattr(obj, attr))}"
233+ return f"def {attr}{method_sig}"
228234
229235 def _get_line(key: str) -> str:
230236 val = self._objstr(getattr(obj, key), memo, indent_level + 1, cfg)

The check that tells the two apart

failpass·tests/test_objstr.py::TestObjStr::test_builtin_method

Check file tests/test_objstr.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it89a9cf8b347ea724cdefe96d01b5017e2c6a4b9f
Broken version dated2024-11-09
Moduleobjprint.objprint
Units changedObjPrint
Fingerprint8b6f90883fd8edef
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in gaogaotiantian/objprint