summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/editor.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-05-24 12:46:22 (GMT)
committerGitHub <noreply@github.com>2023-05-24 12:46:22 (GMT)
commit5e1799ea2e6ce96dbaba380f41f37b3856e43354 (patch)
treee90d7f07bc419364ce94025a17ffb4ac037817b5 /Lib/idlelib/editor.py
parentb151660883864392c0e37972efde232b46a36589 (diff)
downloadcpython-5e1799ea2e6ce96dbaba380f41f37b3856e43354.zip
cpython-5e1799ea2e6ce96dbaba380f41f37b3856e43354.tar.gz
cpython-5e1799ea2e6ce96dbaba380f41f37b3856e43354.tar.bz2
[3.12] gh-104719: IDLE - test existence of all tokenize references. (GH-104767) (#104844)
gh-104719: IDLE - test existence of all tokenize references. (GH-104767) Class editor.IndentSearcher contains all editor references to tokenize module. Module io tokenize reference cover those other modules. (cherry picked from commit e561c09975bf67ad8bb67c56a81e30a9165bcc84) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib/idlelib/editor.py')
-rw-r--r--Lib/idlelib/editor.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py
index df36be87..69b27d0 100644
--- a/Lib/idlelib/editor.py
+++ b/Lib/idlelib/editor.py
@@ -1571,7 +1571,7 @@ class EditorWindow:
# blocks are found).
def guess_indent(self):
- opener, indented = IndentSearcher(self.text, self.tabwidth).run()
+ opener, indented = IndentSearcher(self.text).run()
if opener and indented:
raw, indentsmall = get_line_indent(opener, self.tabwidth)
raw, indentlarge = get_line_indent(indented, self.tabwidth)
@@ -1609,15 +1609,10 @@ def get_line_indent(line, tabwidth):
class IndentSearcher:
+ "Manage initial indent guess, returned by run method."
- # .run() chews over the Text widget, looking for a block opener
- # and the stmt following it. Returns a pair,
- # (line containing block opener, line containing stmt)
- # Either or both may be None.
-
- def __init__(self, text, tabwidth):
+ def __init__(self, text):
self.text = text
- self.tabwidth = tabwidth
self.i = self.finished = 0
self.blkopenline = self.indentedline = None
@@ -1633,7 +1628,8 @@ class IndentSearcher:
def tokeneater(self, type, token, start, end, line,
INDENT=tokenize.INDENT,
NAME=tokenize.NAME,
- OPENERS=('class', 'def', 'for', 'if', 'try', 'while')):
+ OPENERS=('class', 'def', 'for', 'if', 'match', 'try',
+ 'while', 'with')):
if self.finished:
pass
elif type == NAME and token in OPENERS:
@@ -1643,6 +1639,10 @@ class IndentSearcher:
self.finished = 1
def run(self):
+ """Return 2 lines containing block opener and and indent.
+
+ Either the indent line or both may be None.
+ """
try:
tokens = tokenize.generate_tokens(self.readline)
for token in tokens:
@@ -1654,6 +1654,7 @@ class IndentSearcher:
### end autoindent code ###
+
def prepstr(s):
"""Extract the underscore from a string.