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 Jul 7, 2023
1 parent e1c2e34 commit 8ccc88a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/pdbpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8ccc88a

Please sign in to comment.