8000 gh-117174: Add a new route in linecache to fetch interactive source code by pablogsal · Pull Request #117500 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117174: Add a new route in linecache to fetch interactive source code #117500

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

Merged
merged 8 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Several fixes
  • Loading branch information
pablogsal committed Feb 13, 2025
commit 568304b895da2f17276ff9618c7cf27c0f7c9aad
9 changes: 5 additions & 4 deletions Lib/linecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ def _getline_from_code(filename, lineno, module_globals=None):


def _getlines_from_code(code, module_globals=None):
if code in _interactive_cache:
entry = _interactive_cache[code]
code_id = id(code)
if code_id in _interactive_cache:
entry = _interactive_cache[code_id]
if len(entry) != 1:
return _interactive_cache[code][2]
return _interactive_cache[code_id][2]
return []


Expand Down Expand Up @@ -226,4 +227,4 @@ def _register_code(code, string, name):
for const in code.co_consts:
if isinstance(const, type(code)):
stack.append(const)
_interactive_cache[code] = entry
_interactive_cache[id(code)] = entry
3 changes: 2 additions & 1 deletion Lib/test/test_gdb/gdb_sample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Sample script for use by test_gdb
from _typing import _idfunc

def foo(a, b, c):
bar(a=a, b=b, c=c)
Expand All @@ -7,6 +8,6 @@ def bar(a, b, c):
baz(a, b, c)

def baz(*args):
id(42)
_idfunc(42)

foo(1, 2, 3)
2 changes: 1 addition & 1 deletion Lib/test/test_gdb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'python-gdb.py')

SAMPLE_SCRIPT = os.path.join(os.path.dirname(__file__), 'gdb_sample.py')
BREAKPOINT_FN = 'builtin_id'
BREAKPOINT_FN = '_typing__idfunc'

PYTHONHASHSEED = '123'

Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1821,9 +1821,9 @@ def test_encoding_warning(self):
cp = subprocess.run([sys.executable, "-Xwarn_default_encoding", "-c", code],
capture_output=True)
lines = cp.stderr.splitlines()
self.assertEqual(len(lines), 4, lines)
self.assertEqual(len(lines), 2, lines)
self.assertTrue(lines[0].startswith(b"<string>:2: EncodingWarning: "))
self.assertTrue(lines[2].startswith(b"<string>:3: EncodingWarning: "))
self.assertTrue(lines[1].startswith(b"<string>:3: EncodingWarning: "))


def _get_test_grp_name():
Expand Down
0