diff --git a/src/pdbpp.py b/src/pdbpp.py index c64aa220..c290cfa2 100644 --- a/src/pdbpp.py +++ b/src/pdbpp.py @@ -131,6 +131,15 @@ def rebind_globals(func, newglobals): _newfunc(func.func, newglobals), *func.args, **func.keywords ) + # Python 3.11 + _pdb = __import__("pdb", fromlist=("_ModuleTarget", "_ScriptTarget")) + if ( + hasattr(_pdb, '_ModuleTarget') + and hasattr(_pdb, '_ScriptTarget') + and func.__name__ in ("_ModuleTarget", "_ScriptTarget") + ): + return func + raise ValueError("cannot handle func {!r}".format(func)) @@ -2199,7 +2208,16 @@ 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(): +for name in ( + "run", + "runeval", + "runctx", + "runcall", + "main", + "set_trace", + "_ModuleTarget", # Python 3.11 + "_ScriptTarget", # Python 3.11 +): func = getattr(pdb, name) globals()[name] = rebind_globals(func, globals()) del name, func