-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-57537: Support breakpoints for zipimport modules on pdb #130290
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| import textwrap | ||
| import linecache | ||
| import zipapp | ||
| import zipfile | ||
|
|
||
| from contextlib import ExitStack, redirect_stdout | ||
| from io import StringIO | ||
|
|
@@ -4199,6 +4200,38 @@ def f(x): | |
| self.assertIn('42', stdout) | ||
| self.assertIn('return x + 1', stdout) | ||
|
|
||
| def test_zipimport(self): | ||
| with os_helper.temp_dir() as temp_dir: | ||
| os.mkdir(os.path.join(temp_dir, 'source')) | ||
| zipmodule = textwrap.dedent( | ||
| """ | ||
| def bar(x): | ||
| return x + 1 | ||
| """ | ||
| ) | ||
| script = textwrap.dedent( | ||
| f""" | ||
| import sys; sys.path.insert(0, {repr(os.path.join(temp_dir, 'zipmodule.zip'))}) | ||
| import foo | ||
| foo.bar(41) | ||
| """ | ||
| ) | ||
|
|
||
| with zipfile.ZipFile(os.path.join(temp_dir, 'zipmodule.zip'), 'w') as zf: | ||
| zf.writestr('foo.py', zipmodule) | ||
| with open(os.path.join(temp_dir, 'script.py'), 'w') as f: | ||
| f.write(script) | ||
|
|
||
| stdout, _ = self._run_pdb([os.path.join(temp_dir, 'script.py')], '\n'.join([ | ||
| 'n', | ||
| 'n', | ||
| 'b foo.bar', | ||
| 'c', | ||
| 'p x + x', | ||
| 'q' | ||
| ])) | ||
| self.assertIn('82', stdout) | ||
|
||
|
|
||
|
|
||
| class ChecklineTests(unittest.TestCase): | ||
| def setUp(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Support breakpoints for :mod:`zipimport` modules on :mod:`pdb` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably call this func_globals. Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to match the name for linecache. It is a module globals acquired from a function, and the part matters is about the module (loader and stuff).