Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3.11 breaks pdbpp -m #516

Open
monochromec opened this issue Feb 17, 2023 · 11 comments · May be fixed by #521
Open

python3.11 breaks pdbpp -m #516

monochromec opened this issue Feb 17, 2023 · 11 comments · May be fixed by #521

Comments

@monochromec
Copy link

Invoking Python 3.11 with -mpdb results in

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/homebrew/lib/python3.11/site-packages/_pdbpp_path_hack/pdb.py", line 5, in <module>
    exec(compile(f.read(), pdb_path, 'exec'))
  File "/opt/homebrew/lib/python3.11/site-packages/pdb.py", line 1306, in <module>
    pdb.main()
  File "/opt/homebrew/Cellar/python@3.11/3.11.2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pdb.py", line 1759, in main
    cls = _ModuleTarget if module_indicated else _ScriptTarget
                                                 ^^^^^^^^^^^^^
NameError: name '_ScriptTarget' is not defined

This problem can be reproduced on Ubuntu (22.04, Python 3.11.0) and Homebrew (with Python 3.11.2, see backtrace above). Please let me know if more info is required.

@blueyed
Copy link
Collaborator

blueyed commented Feb 20, 2023

This works with pdb++ from the master branch, please test it there.

@monochromec
Copy link
Author

Installing this via setup.py install causes the egg directory to be stored in the corresponding site-packages directory but the _pdbpp_path_hack fails to be picked up correctly. Hence no pdb++ inclusion... What am I doing wrong?

Including this in PYTHONPATH as suggested by the README results in the issue as reported.

@blueyed
Copy link
Collaborator

blueyed commented Feb 20, 2023

Installation via pip should work (via local checkout (pip install …/pdpbb or pip install 'git+https://github.com/pdbpp/pdbpp@master').

@monochromec
Copy link
Author

Unfortunately installing this via pip and the GH URL results in the same error reported initially. The _pdbpp_path_hackdirectory is created in site-packages but the pdb.py inclusion still fails. Please let me know if more info is required.

@blueyed
Copy link
Collaborator

blueyed commented Feb 24, 2023

Confirmed.

This fixes it, but likely needs checks to handle / skip it with older Pythons, and I am not sure if classes should be used as-is really:

 src/pdbpp.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git i/src/pdbpp.py w/src/pdbpp.py
index c64aa22..0022c5d 100644
--- i/src/pdbpp.py
+++ w/src/pdbpp.py
@@ -131,6 +131,10 @@ def rebind_globals(func, newglobals):
             _newfunc(func.func, newglobals), *func.args, **func.keywords
         )
 
+    if isinstance(func, type):
+        # Classes (_ModuleTarget, _ScriptTarget).
+        return func
+
     raise ValueError("cannot handle func {!r}".format(func))
 
 
@@ -2199,7 +2203,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

@blueyed blueyed changed the title python3.11 breaks pdbpp python3.11 breaks pdbpp -m Feb 24, 2023
@monochromec
Copy link
Author

Confirmed that this fixes the issue on 3.11. Once it's entered pypi, I might do a regression on older Python versions.

@blueyed
Copy link
Collaborator

blueyed commented Feb 27, 2023

Let's keep the issue open until a fix is committed.

@blueyed blueyed reopened this Feb 27, 2023
@jamilraichouni
Copy link

Don't know if it helps. When I pip install 'git+https://github.com/pdbpp/pdbpp@master' and then run some python -mpdb (...) with a Python 3.11.1 I see:

Traceback (most recent call last):                                                                                                                                                                                                                                               
  File "<frozen runpy>", line 198, in _run_module_as_main                                                                                                                                                                                                                        
  File "<frozen runpy>", line 88, in _run_code                                                                                                                                                                                                                                   
  File "/home/nörd/.pyenv/versions/rm-bridge-polarion/lib/python3.11/site-packages/_pdbpp_path_hack/pdb.py", line 17, in <module>                                                                                                                                                
    exec(compile(f.read(), pdb_path, 'exec'))                                                                                                                                                                                                                                    
  File "/home/nörd/.pyenv/versions/rm-bridge-polarion/lib/python3.11/site-packages/pdbpp.py", line 2328, in <module>                                                                                                                                                             
    pdbpp.main()                                                                                                                                                                                                                                                                 
  File "/home/nörd/.pyenv/versions/3.11.1/lib/python3.11/pdb.py", line 1759, in main                                                                                                                                                                                             
    cls = _ModuleTarget if module_indicated else _ScriptTarget                                                                                                                                                                                                                   
          ^^^^^^^^^^^^^                                                                                                                                                                                                                                                          
NameError: name '_ModuleTarget' is not defined

@tgy
Copy link

tgy commented May 23, 2023

I get the same error! The patch fixes it.

@petobens
Copy link
Contributor

Let's keep the issue open until a fix is committed.

@blueyed can you commit your patch? It seems to be working.

@tgy
Copy link

tgy commented May 26, 2023

@petobens @blueyed see #520

bretello added a commit to bretello/pdbpp that referenced this issue Jul 7, 2023
based on the changes in proposed in pdbpp#516 and pdbpp#520

fixes pdbpp#516
bretello added a commit to bretello/pdbpp that referenced this issue Jul 7, 2023
based on the changes in proposed in pdbpp#516 and pdbpp#520

fixes pdbpp#516
bretello added a commit to bretello/pdbpp that referenced this issue Jul 7, 2023
based on the changes in proposed in pdbpp#516 and pdbpp#520

fixes pdbpp#516
@bretello bretello linked a pull request Jul 7, 2023 that will close this issue
bretello added a commit to bretello/pdbpp that referenced this issue Oct 29, 2023
based on the changes in proposed in pdbpp#516 and pdbpp#520

fixes pdbpp#516
bretello added a commit to bretello/pdbpp that referenced this issue Oct 29, 2023
based on the changes in proposed in pdbpp#516 and pdbpp#520

fixes pdbpp#516
bretello added a commit to bretello/pdbpp that referenced this issue Nov 7, 2023
based on the changes in proposed in pdbpp#516 and pdbpp#520

fixes pdbpp#516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants