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
gh-93696: Locate frozen module source with __file__ #93697
base: main
Are you sure you want to change the base?
Conversation
Edit: I have now added a test to this PR, see follow-up comment
click to see patchdiff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 0141b739c2..894f3e9099 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -532,6 +532,40 @@ def test_list_commands():
(Pdb) continue
"""
+def test_frozen_list():
+ '''Test the list command on frozen stdlib modules
+
+ >>> def test_function():
+ ... import importlib._bootstrap
+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ ... importlib._bootstrap._resolve_name("os", ".", 1)
+
+ >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
+ ... 'step',
+ ... 'list',
+ ... 'continue',
+ ... ]):
+ ... test_function()
+ > <doctest test.test_pdb.test_frozen_list[0]>(4)test_function()
+ -> importlib._bootstrap._resolve_name("os", ".", 1)
+ (Pdb) step
+ --Call--
+ > <frozen importlib._bootstrap>(1037)_resolve_name()
+ (Pdb) list
+ 1032 def __exit__(self, exc_type, exc_value, exc_traceback):
+ 1033 """Release the import lock regardless of any raised exceptions."""
+ 1034 _imp.release_lock()
+ 1035
+ 1036
+ 1037 -> def _resolve_name(name, package, level):
+ 1038 """Resolve a relative module name to an absolute one."""
+ 1039 bits = package.rsplit('.', level - 1)
+ 1040 if len(bits) < level:
+ 1041 raise ImportError('attempted relative import beyond top-level package')
+ 1042 base = bits[0]
+ (Pdb) continue
+ '''
+
def test_pdb_whatis_command():
"""Test the whatis command |
Updated with a test that creates a module that suitably fakes the behavior of functions inside of frozen modules, in the sense that |
See #93696, this patch allows
pdb
to locate the source for frozen stdlib modules. With the patch applied, the output ofpdb
is as expected:I am not particularly familiar with the frozen module system so I'm not sure if there are edge cases where this will produce undesirable behavior, but thought that I would send it upstream just in case😅