From 0b3c3b8eac6da570a4ecb91c5abe2aa83c9150e6 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Wed, 5 Apr 2023 08:59:31 -0700 Subject: [PATCH 1/3] Fixed zero lineno issue for pdb Co-authored-by: Artem Mukhin --- Lib/pdb.py | 6 +++++ Lib/test/test_pdb.py | 25 +++++++++++++++++++ ...-04-05-01-28-53.gh-issue-103225.QD3JVU.rst | 1 + 3 files changed, 32 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst diff --git a/Lib/pdb.py b/Lib/pdb.py index 3a06cd00ad2bf1..b19efdd87ea96b 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1352,6 +1352,9 @@ def do_longlist(self, arg): breaklist = self.get_file_breaks(filename) try: lines, lineno = inspect.getsourcelines(self.curframe) + # inspect.getsourcelines() returns lineno = 0 for + # module-level frame which breaks our code print line number + lineno = max(1, lineno) except OSError as err: self.error(err) return @@ -1368,6 +1371,9 @@ def do_source(self, arg): return try: lines, lineno = inspect.getsourcelines(obj) + # inspect.getsourcelines() returns lineno = 0 for + # module-level frame which breaks our code print line number + lineno = max(1, lineno) except (OSError, TypeError) as err: self.error(err) return diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index de2bab46495729..9ad9a1c52ac102 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1675,6 +1675,31 @@ def test_pdb_issue_gh_101673(): (Pdb) continue """ +def test_pdb_issue_gh_103225(): + """See GH-103225 + + Make sure longlist uses 1-based line numbers in frames that correspond to a module + + >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE + ... 'longlist', + ... 'continue' + ... ]): + ... a = 1 + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... b = 2 + > (7)() + -> b = 2 + (Pdb) longlist + 1 with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE + 2 'longlist', + 3 'continue' + 4 ]): + 5 a = 1 + 6 import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + 7 -> b = 2 + (Pdb) continue + """ + @support.requires_subprocess() class PdbTestCase(unittest.TestCase): diff --git a/Misc/NEWS.d/next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst b/Misc/NEWS.d/next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst new file mode 100644 index 00000000000000..7ee5b764a265b2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst @@ -0,0 +1 @@ +Fixed the line number display bug on modules for :mod:`pdb` From b157545dce202a61d878366c3ae7f6343d27c147 Mon Sep 17 00:00:00 2001 From: gaogaotiantian Date: Thu, 6 Apr 2023 11:20:15 -0700 Subject: [PATCH 2/3] Update Misc/NEWS.d/next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- .../next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst b/Misc/NEWS.d/next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst index 7ee5b764a265b2..5d1a063acdeb8c 100644 --- a/Misc/NEWS.d/next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst +++ b/Misc/NEWS.d/next/Library/2023-04-05-01-28-53.gh-issue-103225.QD3JVU.rst @@ -1 +1 @@ -Fixed the line number display bug on modules for :mod:`pdb` +Fix a bug in :mod:`pdb` when displaying line numbers of module-level source code. From e7dd1f67cd4b6394ab1a0b5c39c44e47264939f2 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 6 Apr 2023 16:19:29 -0700 Subject: [PATCH 3/3] Create a helper function for getsourcelines --- Lib/pdb.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index b19efdd87ea96b..e043b0d46f7dd0 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1351,10 +1351,7 @@ def do_longlist(self, arg): filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: - lines, lineno = inspect.getsourcelines(self.curframe) - # inspect.getsourcelines() returns lineno = 0 for - # module-level frame which breaks our code print line number - lineno = max(1, lineno) + lines, lineno = self._getsourcelines(self.curframe) except OSError as err: self.error(err) return @@ -1370,10 +1367,7 @@ def do_source(self, arg): except: return try: - lines, lineno = inspect.getsourcelines(obj) - # inspect.getsourcelines() returns lineno = 0 for - # module-level frame which breaks our code print line number - lineno = max(1, lineno) + lines, lineno = self._getsourcelines(obj) except (OSError, TypeError) as err: self.error(err) return @@ -1668,6 +1662,16 @@ def _compile_error_message(self, expr): return _rstr(self._format_exc(exc)) return "" + def _getsourcelines(self, obj): + # GH-103319 + # inspect.getsourcelines() returns lineno = 0 for + # module-level frame which breaks our code print line number + # This method should be replaced by inspect.getsourcelines(obj) + # once this bug is fixed in inspect + lines, lineno = inspect.getsourcelines(obj) + lineno = max(1, lineno) + return lines, lineno + # Collect all command help into docstring, if not run with -OO if __doc__ is not None: 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