mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
bpo-28528: Fix pdb.checkline() attribute error when 'curframe' is None. (GH-25438) (#26050)
Co-authored-by: Thomas Kluyver <takowl@gmail.com>
(cherry picked from commit 8563a7052c)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
parent
6098214b98
commit
c90ed8e2e7
3 changed files with 42 additions and 1 deletions
|
|
@ -752,7 +752,8 @@ def checkline(self, filename, lineno):
|
||||||
"""
|
"""
|
||||||
# this method should be callable before starting debugging, so default
|
# this method should be callable before starting debugging, so default
|
||||||
# to "no globals" if there is no current frame
|
# to "no globals" if there is no current frame
|
||||||
globs = self.curframe.f_globals if hasattr(self, 'curframe') else None
|
frame = getattr(self, 'curframe', None)
|
||||||
|
globs = frame.f_globals if frame else None
|
||||||
line = linecache.getline(filename, lineno, globs)
|
line = linecache.getline(filename, lineno, globs)
|
||||||
if not line:
|
if not line:
|
||||||
self.message('End of file')
|
self.message('End of file')
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
import subprocess
|
import subprocess
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import linecache
|
||||||
|
|
||||||
from contextlib import ExitStack
|
from contextlib import ExitStack
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
@ -1807,10 +1808,47 @@ def test_issue42383(self):
|
||||||
self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected)
|
self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected)
|
||||||
|
|
||||||
|
|
||||||
|
class ChecklineTests(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
linecache.clearcache() # Pdb.checkline() uses linecache.getline()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os_helper.unlink(os_helper.TESTFN)
|
||||||
|
|
||||||
|
def test_checkline_before_debugging(self):
|
||||||
|
with open(os_helper.TESTFN, "w") as f:
|
||||||
|
f.write("print(123)")
|
||||||
|
db = pdb.Pdb()
|
||||||
|
self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1)
|
||||||
|
|
||||||
|
def test_checkline_after_reset(self):
|
||||||
|
with open(os_helper.TESTFN, "w") as f:
|
||||||
|
f.write("print(123)")
|
||||||
|
db = pdb.Pdb()
|
||||||
|
db.reset()
|
||||||
|
self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1)
|
||||||
|
|
||||||
|
def test_checkline_is_not_executable(self):
|
||||||
|
with open(os_helper.TESTFN, "w") as f:
|
||||||
|
# Test for comments, docstrings and empty lines
|
||||||
|
s = textwrap.dedent("""
|
||||||
|
# Comment
|
||||||
|
\"\"\" docstring \"\"\"
|
||||||
|
''' docstring '''
|
||||||
|
|
||||||
|
""")
|
||||||
|
f.write(s)
|
||||||
|
db = pdb.Pdb()
|
||||||
|
num_lines = len(s.splitlines()) + 2 # Test for EOF
|
||||||
|
for lineno in range(num_lines):
|
||||||
|
self.assertFalse(db.checkline(os_helper.TESTFN, lineno))
|
||||||
|
|
||||||
|
|
||||||
def load_tests(*args):
|
def load_tests(*args):
|
||||||
from test import test_pdb
|
from test import test_pdb
|
||||||
suites = [
|
suites = [
|
||||||
unittest.makeSuite(PdbTestCase),
|
unittest.makeSuite(PdbTestCase),
|
||||||
|
unittest.makeSuite(ChecklineTests),
|
||||||
doctest.DocTestSuite(test_pdb)
|
doctest.DocTestSuite(test_pdb)
|
||||||
]
|
]
|
||||||
return unittest.TestSuite(suites)
|
return unittest.TestSuite(suites)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix a bug in :mod:`pdb` where :meth:`~pdb.Pdb.checkline` raises
|
||||||
|
:exc:`AttributeError` if it is called after :meth:`~pdb.Pdb.reset`.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue