Skip to content

Commit 70ddc90

Browse files
Add comments and simplify the code.
1 parent ce973ab commit 70ddc90

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

Lib/inspect.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ class BlockFinder:
10561056
"""Provide a tokeneater() method to detect the end of a code block."""
10571057
def __init__(self):
10581058
self.indent = 0
1059-
self.islambda = False
1059+
self.islambda = False # used also for generator expressions
10601060
self.started = False
10611061
self.passline = False
10621062
self.indecorator = False
@@ -1065,21 +1065,18 @@ def __init__(self):
10651065

10661066
def tokeneater(self, type, token, srowcol, erowcol, line):
10671067
if not self.started and not self.indecorator:
1068-
if type != tokenize.INDENT:
1069-
# skip any decorators
1070-
if token == "@":
1071-
self.indecorator = True
1072-
elif token == "async":
1073-
pass
1074-
# look for the first "def", "class" or "lambda"
1075-
elif token in ("def", "class", "lambda"):
1076-
if token == "lambda":
1077-
self.islambda = True
1078-
self.started = True
1079-
else:
1080-
self.islambda = True
1081-
self.started = True
1082-
self.passline = True # skip to the end of the line
1068+
if type == tokenize.INDENT or token == "async":
1069+
pass
1070+
# skip any decorators
1071+
elif token == "@":
1072+
self.indecorator = True
1073+
else:
1074+
# For "def" and "class" scan to the end of the block.
1075+
# For "lambda" and generator expression scan to
1076+
# the end of the logical line.
1077+
self.islambda = token not in ("def", "class")
1078+
self.started = True
1079+
self.passline = True # skip to the end of the line
10831080
elif type == tokenize.NEWLINE:
10841081
self.passline = False # stop skipping when a NEWLINE is seen
10851082
self.last = srowcol[0]

0 commit comments

Comments
 (0)