From 8ccc88abfe9ccfc61d9eb4b72eae59ced2728523 Mon Sep 17 00:00:00 2001 From: bretello Date: Sat, 8 Jul 2023 00:29:32 +0200 Subject: [PATCH] fix python -m pdb on 3.11 based on the changes in proposed in #516 and #520 fixes #516 --- src/pdbpp.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pdbpp.py b/src/pdbpp.py index c64aa220..dc1526b3 100644 --- a/src/pdbpp.py +++ b/src/pdbpp.py @@ -131,6 +131,9 @@ def rebind_globals(func, newglobals): _newfunc(func.func, newglobals), *func.args, **func.keywords ) + if sys.version_info >= (3, 11) and func.__name__ in ("_ModuleTarget", "_ScriptTarget"): + return func + raise ValueError("cannot handle func {!r}".format(func)) @@ -2199,10 +2202,19 @@ def _remove_bdb_context(evalue): _usage = pdb._usage # copy some functions from pdb.py, but rebind the global dictionary -for name in 'run runeval runctx runcall main set_trace'.split(): +to_rebind = [ + "run", + "runeval", + "runctx", + "runcall", + "main", + "set_trace"] +if sys.version_info >= (3, 11): + to_rebind += ["_ModuleTarget", "_ScriptTarget"] +for name in to_rebind: func = getattr(pdb, name) globals()[name] = rebind_globals(func, globals()) -del name, func +del name, func, to_rebind # Post-Mortem interface