Skip to content

Commit dfa1144

Browse files
bpo-32905: IDLE - remove unused code in pyparse module (GH-5807)
dump is similar to print but less flexible. lastopenbracketpos is now always initialized in _study2, as was stmt_bracketing, so the class settings are not needed. get_last_open_bracket_pos is never called. (cherry picked from commit 451d1ed) Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent bc2e110 commit dfa1144

File tree

3 files changed

+8
-50
lines changed

3 files changed

+8
-50
lines changed

Lib/idlelib/idle_test/test_pyparse.py

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""Unittest for idlelib.pyparse.py."""
1+
"""Unittest for idlelib.pyparse.py.
2+
3+
Coverage: 97%
4+
"""
25

36
from collections import namedtuple
47
import unittest
@@ -272,8 +275,6 @@ def test_study2(self):
272275
)
273276

274277
for test in tests:
275-
# There is a bug where this is carried forward from last item.
276-
p.lastopenbracketpos = None
277278
with self.subTest(string=test.string):
278279
setstr(test.string)
279280
study()
@@ -464,33 +465,6 @@ def test_is_block_closer(self):
464465
setstr(test.string)
465466
test.assert_(closer())
466467

467-
def test_get_last_open_bracket_pos(self):
468-
eq = self.assertEqual
469-
p = self.parser
470-
setstr = p.set_str
471-
openbracket = p.get_last_open_bracket_pos
472-
473-
TestInfo = namedtuple('TestInfo', ['string', 'position'])
474-
tests = (
475-
TestInfo('', None),
476-
TestInfo('a\n', None),
477-
TestInfo('# (\n', None),
478-
TestInfo('""" (\n', None),
479-
TestInfo('a = (1 + 2) - 5 *\\\n', None),
480-
TestInfo('\n def function1(self, a,\n', 17),
481-
TestInfo('\n def function1(self, a, # End of line comment.\n', 17),
482-
TestInfo('{)(]\n', None),
483-
TestInfo('(((((((((()))))))\n', 2),
484-
TestInfo('(((((((((())\n)))\n))\n', 2),
485-
)
486-
487-
for test in tests:
488-
# There is a bug where the value is carried forward from last item.
489-
p.lastopenbracketpos = None
490-
with self.subTest(string=test.string):
491-
setstr(test.string)
492-
eq(openbracket(), test.position)
493-
494468
def test_get_last_stmt_bracketing(self):
495469
eq = self.assertEqual
496470
p = self.parser

Lib/idlelib/pyparse.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
(C_NONE, C_BACKSLASH, C_STRING_FIRST_LINE,
1919
C_STRING_NEXT_LINES, C_BRACKET) = range(5)
2020

21-
if 0: # for throwaway debugging output
22-
def dump(*stuff):
23-
sys.__stdout__.write(" ".join(map(str, stuff)) + "\n")
24-
2521
# Find what looks like the start of a popular statement.
2622

2723
_synchre = re.compile(r"""
@@ -496,8 +492,7 @@ def _study2(self):
496492
# end while p < q:
497493

498494
self.lastch = lastch
499-
if stack:
500-
self.lastopenbracketpos = stack[-1]
495+
self.lastopenbracketpos = stack[-1] if stack else None
501496
self.stmt_bracketing = tuple(bracketing)
502497

503498
def compute_bracket_indent(self):
@@ -620,22 +615,10 @@ def is_block_closer(self):
620615
self._study2()
621616
return _closere(self.str, self.stmt_start) is not None
622617

623-
# XXX - is this used?
624-
lastopenbracketpos = None
625-
626-
def get_last_open_bracket_pos(self):
627-
"Return index of last open bracket or None."
628-
self._study2()
629-
return self.lastopenbracketpos
630-
631-
# XXX - is this used?
632-
stmt_bracketing = None
633-
634618
def get_last_stmt_bracketing(self):
635-
"""Return a tuple of the structure of the bracketing of the last
636-
interesting statement.
619+
"""Return bracketing structure of the last interesting statement.
637620
638-
Tuple is in the format defined in _study2().
621+
The returned tuple is in the format defined in _study2().
639622
"""
640623
self._study2()
641624
return self.stmt_bracketing
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove unused code in pyparse module.

0 commit comments

Comments
 (0)