Skip to content

Commit

Permalink
fix python -m pdb on 3.11
Browse files Browse the repository at this point in the history
based on the changes in proposed in pdbpp#516 and pdbpp#520

fixes pdbpp#516
  • Loading branch information
bretello committed Oct 29, 2023
1 parent f73253d commit 9267135
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/pdbpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ 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))


Expand Down Expand Up @@ -2165,10 +2171,13 @@ 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
Expand Down

0 comments on commit 9267135

Please sign in to comment.