"""用脚本化 pdb 走一遍断点、单步与打印变量。""" from __future__ import annotations import io import pdb def add(left: int, right: int) -> int: total = left + right return total def scripted() -> str: commands = io.StringIO("n\np total\nc\n") output = io.StringIO() debugger = pdb.Pdb(stdin=commands, stdout=output) debugger.runcall(add, 2, 3) return output.getvalue() def main() -> None: text = scripted() print(text) print(f"printed_total: {'5' in text}") if __name__ == "__main__": main()