From 3acb643098e79d8baa81a2859a2083a14f346afd Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 7 Feb 2023 20:00:39 -0800 Subject: [PATCH 1/6] Use f_code.co_name for module frame checking --- Lib/pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 78d0ce537f1fc2..67f1f56e5ec486 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -109,7 +109,7 @@ def find_function(funcname, filename): def getsourcelines(obj): lines, lineno = inspect.findsource(obj) - if inspect.isframe(obj) and obj.f_globals is obj.f_locals: + if inspect.isframe(obj) and obj.f_code.co_name == "": # must be a module frame: do not try to cut a block out of it return lines, 1 elif inspect.ismodule(obj): From 6cfbe7cbf108d2e14f31dbe92bac88fad9b1faed Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 9 Feb 2023 19:40:42 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst diff --git a/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst b/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst new file mode 100644 index 00000000000000..9bc533e035f5f5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst @@ -0,0 +1 @@ +Fix a pdb bug where `ll` clears the changes to local variables. From bb2d818bcfad963070fd802e0e5cfb6af59132c4 Mon Sep 17 00:00:00 2001 From: gaogaotiantian Date: Thu, 9 Feb 2023 12:03:19 -0800 Subject: [PATCH 3/6] Update 2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst Use double ticks for inline code --- .../next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst b/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst index 9bc533e035f5f5..a79e261411f793 100644 --- a/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst +++ b/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst @@ -1 +1 @@ -Fix a pdb bug where `ll` clears the changes to local variables. +Fix a pdb bug where ``ll`` clears the changes to local variables. From 121e00ba88d12173f1ba6e1f42e4d905c23dffd2 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sat, 11 Mar 2023 18:37:01 -0800 Subject: [PATCH 4/6] Add regression test for the bug --- Lib/test/test_pdb.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 48f419e62fbbed..d91bd0b2f03a0f 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1474,6 +1474,35 @@ def test_pdb_issue_gh_94215(): (Pdb) continue """ +def test_pdb_issue_gh_101673(): + """See GH-101673 + + Make sure ll won't revert local variable assignment + + >>> def test_function(): + ... a = 1 + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + + >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE + ... '!a = 2', + ... 'll', + ... 'p a', + ... 'continue' + ... ]): + ... test_function() + --Return-- + > (3)test_function()->None + -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) !a = 2 + (Pdb) ll + 1 def test_function(): + 2 a = 1 + 3 -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) p a + 2 + (Pdb) continue + """ + @support.requires_subprocess() class PdbTestCase(unittest.TestCase): From 5724f3fd25bbaba40f636a5f72740c680139274e Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sun, 12 Mar 2023 14:53:56 -0700 Subject: [PATCH 5/6] Use inspect.getsourcelines directly --- Lib/pdb.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 67f1f56e5ec486..f11fc55536810f 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -107,15 +107,6 @@ def find_function(funcname, filename): return funcname, filename, lineno return None -def getsourcelines(obj): - lines, lineno = inspect.findsource(obj) - if inspect.isframe(obj) and obj.f_code.co_name == "": - # must be a module frame: do not try to cut a block out of it - return lines, 1 - elif inspect.ismodule(obj): - return lines, 1 - return inspect.getblock(lines[lineno:]), lineno+1 - def lasti2lineno(code, lasti): linestarts = list(dis.findlinestarts(code)) linestarts.reverse() @@ -1357,7 +1348,7 @@ def do_longlist(self, arg): filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: - lines, lineno = getsourcelines(self.curframe) + lines, lineno = inspect.getsourcelines(self.curframe) except OSError as err: self.error(err) return @@ -1373,7 +1364,7 @@ def do_source(self, arg): except: return try: - lines, lineno = getsourcelines(obj) + lines, lineno = inspect.getsourcelines(obj) except (OSError, TypeError) as err: self.error(err) return From ef602d8f362abdccbfb68f37d637627030dd0404 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Sun, 12 Mar 2023 22:26:38 +0000 Subject: [PATCH 6/6] tweak news --- .../next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst b/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst index a79e261411f793..4e673ba9811568 100644 --- a/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst +++ b/Misc/NEWS.d/next/Library/2023-02-09-19-40-41.gh-issue-101673.mX-Ppq.rst @@ -1 +1 @@ -Fix a pdb bug where ``ll`` clears the changes to local variables. +Fix a :mod:`pdb` bug where ``ll`` clears the changes to local variables. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy