Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ def newline_and_indent_event(self, event):
startat = max(lno - context, 1)
startatindex = repr(startat) + ".0"
rawtext = text.get(startatindex, "insert")
y.set_str(rawtext)
y.set_code(rawtext)
bod = y.find_good_parse_start(
self.context_use_ps1,
self._build_char_in_string_func(startatindex))
Expand All @@ -1316,7 +1316,7 @@ def newline_and_indent_event(self, event):
else:
startatindex = "1.0"
rawtext = text.get(startatindex, "insert")
y.set_str(rawtext)
y.set_code(rawtext)
y.set_lo(0)

c = y.get_continuation_type()
Expand Down
8 changes: 4 additions & 4 deletions Lib/idlelib/hyperparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def index2line(index):
# at end. We add a space so that index won't be at end
# of line, so that its status will be the same as the
# char before it, if should.
parser.set_str(text.get(startatindex, stopatindex)+' \n')
parser.set_code(text.get(startatindex, stopatindex)+' \n')
bod = parser.find_good_parse_start(
editwin._build_char_in_string_func(startatindex))
if bod is not None or startat == 1:
Expand All @@ -60,12 +60,12 @@ def index2line(index):
# We add the newline because PyParse requires it. We add a
# space so that index won't be at end of line, so that its
# status will be the same as the char before it, if should.
parser.set_str(text.get(startatindex, stopatindex)+' \n')
parser.set_code(text.get(startatindex, stopatindex)+' \n')
parser.set_lo(0)

# We want what the parser has, minus the last newline and space.
self.rawtext = parser.str[:-2]
# Parser.str apparently preserves the statement we are in, so
self.rawtext = parser.code[:-2]
# Parser.code apparently preserves the statement we are in, so
# that stopatindex can be used to synchronize the string with
# the text box indices.
self.stopatindex = stopatindex
Expand Down
70 changes: 35 additions & 35 deletions Lib/idlelib/idle_test/test_pyparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,32 @@ def test_init(self):
self.assertEqual(self.parser.indentwidth, 4)
self.assertEqual(self.parser.tabwidth, 4)

def test_set_str(self):
def test_set_code(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code

# Not empty and doesn't end with newline.
with self.assertRaises(AssertionError):
setstr('a')
setcode('a')

tests = ('',
'a\n')

for string in tests:
with self.subTest(string=string):
setstr(string)
eq(p.str, string)
setcode(string)
eq(p.code, string)
eq(p.study_level, 0)

def test_find_good_parse_start(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code
start = p.find_good_parse_start

# Split def across lines.
setstr('"""This is a module docstring"""\n'
setcode('"""This is a module docstring"""\n'
'class C():\n'
' def __init__(self, a,\n'
' b=True):\n'
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_find_good_parse_start(self):

# Code without extra line break in def line - mostly returns the same
# values.
setstr('"""This is a module docstring"""\n'
setcode('"""This is a module docstring"""\n'
'class C():\n'
' def __init__(self, a, b=True):\n'
' pass\n'
Expand All @@ -138,19 +138,19 @@ def test_set_lo(self):
' pass\n'
)
p = self.parser
p.set_str(code)
p.set_code(code)

# Previous character is not a newline.
with self.assertRaises(AssertionError):
p.set_lo(5)

# A value of 0 doesn't change self.str.
# A value of 0 doesn't change self.code.
p.set_lo(0)
self.assertEqual(p.str, code)
self.assertEqual(p.code, code)

# An index that is preceded by a newline.
p.set_lo(44)
self.assertEqual(p.str, code[44:])
self.assertEqual(p.code, code[44:])

def test_tran(self):
self.assertEqual('\t a([{b}])b"c\'d\n'.translate(self.parser._tran),
Expand All @@ -159,7 +159,7 @@ def test_tran(self):
def test_study1(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code
study = p._study1

(NONE, BACKSLASH, FIRST, NEXT, BRACKET) = range(5)
Expand Down Expand Up @@ -197,7 +197,7 @@ def test_study1(self):

for test in tests:
with self.subTest(string=test.string):
setstr(test.string) # resets study_level
setcode(test.string) # resets study_level
study()
eq(p.study_level, 1)
eq(p.goodlines, test.goodlines)
Expand All @@ -209,7 +209,7 @@ def test_study1(self):
def test_get_continuation_type(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code
gettype = p.get_continuation_type

(NONE, BACKSLASH, FIRST, NEXT, BRACKET) = range(5)
Expand All @@ -224,13 +224,13 @@ def test_get_continuation_type(self):

for test in tests:
with self.subTest(string=test.string):
setstr(test.string)
setcode(test.string)
eq(gettype(), test.continuation)

def test_study2(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code
study = p._study2

TestInfo = namedtuple('TestInfo', ['string', 'start', 'end', 'lastch',
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_study2(self):

for test in tests:
with self.subTest(string=test.string):
setstr(test.string)
setcode(test.string)
study()
eq(p.study_level, 2)
eq(p.stmt_start, test.start)
Expand All @@ -291,7 +291,7 @@ def test_study2(self):
def test_get_num_lines_in_stmt(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code
getlines = p.get_num_lines_in_stmt

TestInfo = namedtuple('TestInfo', ['string', 'lines'])
Expand All @@ -307,19 +307,19 @@ def test_get_num_lines_in_stmt(self):
)

# Blank string doesn't have enough elements in goodlines.
setstr('')
setcode('')
with self.assertRaises(IndexError):
getlines()

for test in tests:
with self.subTest(string=test.string):
setstr(test.string)
setcode(test.string)
eq(getlines(), test.lines)

def test_compute_bracket_indent(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code
indent = p.compute_bracket_indent

TestInfo = namedtuple('TestInfo', ['string', 'spaces'])
Expand All @@ -340,18 +340,18 @@ def test_compute_bracket_indent(self):
)

# Must be C_BRACKET continuation type.
setstr('def function1(self, a, b):\n')
setcode('def function1(self, a, b):\n')
with self.assertRaises(AssertionError):
indent()

for test in tests:
setstr(test.string)
setcode(test.string)
eq(indent(), test.spaces)

def test_compute_backslash_indent(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code
indent = p.compute_backslash_indent

# Must be C_BACKSLASH continuation type.
Expand All @@ -361,7 +361,7 @@ def test_compute_backslash_indent(self):
)
for string in errors:
with self.subTest(string=string):
setstr(string)
setcode(string)
with self.assertRaises(AssertionError):
indent()

Expand All @@ -384,13 +384,13 @@ def test_compute_backslash_indent(self):
)
for test in tests:
with self.subTest(string=test.string):
setstr(test.string)
setcode(test.string)
eq(indent(), test.spaces)

def test_get_base_indent_string(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code
baseindent = p.get_base_indent_string

TestInfo = namedtuple('TestInfo', ['string', 'indent'])
Expand All @@ -405,14 +405,14 @@ def test_get_base_indent_string(self):

for test in tests:
with self.subTest(string=test.string):
setstr(test.string)
setcode(test.string)
eq(baseindent(), test.indent)

def test_is_block_opener(self):
yes = self.assertTrue
no = self.assertFalse
p = self.parser
setstr = p.set_str
setcode = p.set_code
opener = p.is_block_opener

TestInfo = namedtuple('TestInfo', ['string', 'assert_'])
Expand All @@ -433,14 +433,14 @@ def test_is_block_opener(self):

for test in tests:
with self.subTest(string=test.string):
setstr(test.string)
setcode(test.string)
test.assert_(opener())

def test_is_block_closer(self):
yes = self.assertTrue
no = self.assertFalse
p = self.parser
setstr = p.set_str
setcode = p.set_code
closer = p.is_block_closer

TestInfo = namedtuple('TestInfo', ['string', 'assert_'])
Expand All @@ -462,13 +462,13 @@ def test_is_block_closer(self):

for test in tests:
with self.subTest(string=test.string):
setstr(test.string)
setcode(test.string)
test.assert_(closer())

def test_get_last_stmt_bracketing(self):
eq = self.assertEqual
p = self.parser
setstr = p.set_str
setcode = p.set_code
bracketing = p.get_last_stmt_bracketing

TestInfo = namedtuple('TestInfo', ['string', 'bracket'])
Expand All @@ -489,7 +489,7 @@ def test_get_last_stmt_bracketing(self):

for test in tests:
with self.subTest(string=test.string):
setstr(test.string)
setcode(test.string)
eq(bracketing(), test.bracket)


Expand Down
Loading