@@ -127,16 +127,25 @@ def _raw_parse(self) -> None:
127
127
128
128
# Tokenize, to find excluded suites, to find docstrings, and to find
129
129
# multi-line statements.
130
- indent = 0
131
- exclude_indent = 0
132
- excluding = False
133
- excluding_decorators = False
134
- prev_toktype = token .INDENT
135
- first_line = None
136
- empty = True
137
- first_on_line = True
138
- nesting = 0
139
- prev_ttext = None
130
+
131
+ # The last token seen. Start with INDENT to get module docstrings
132
+ prev_toktype : int = token .INDENT
133
+ # The current number of indents.
134
+ indent : int = 0
135
+ # An exclusion comment will exclude an entire clause at this indent.
136
+ exclude_indent : int = 0
137
+ # Are we currently excluding lines?
138
+ excluding : bool = False
139
+ # Are we excluding decorators now?
140
+ excluding_decorators : bool = False
141
+ # The line number of the first line in a multi-line statement.
142
+ first_line : int = 0
143
+ # Is the file empty?
144
+ empty : bool = True
145
+ # Is this the first token on a line?
146
+ first_on_line : bool = True
147
+ # Parenthesis (and bracket) nesting level.
148
+ nesting : int = 0
140
149
141
150
assert self .text is not None
142
151
tokgen = generate_tokens (self .text )
@@ -180,26 +189,26 @@ def _raw_parse(self) -> None:
180
189
nesting += 1
181
190
elif ttext in ")]}" :
182
191
nesting -= 1
183
- elif toktype == token .STRING and prev_toktype == token . INDENT :
184
- # Strings that are first on an indented line are docstrings.
185
- # (a trick from trace.py in the stdlib.) This works for
186
- # 99.9999% of cases. For the rest (!) see:
187
- # http://stackoverflow.com/questions/1769332/x/1769794#1769794
188
- self .raw_docstrings .update (range (slineno , elineno + 1 ))
192
+ elif toktype == token .STRING :
193
+ if prev_toktype == token . INDENT :
194
+ # Strings that are first on an indented line are docstrings.
195
+ # (a trick from trace.py in the stdlib.) This works for
196
+ # 99.9999% of cases.
197
+ self .raw_docstrings .update (range (slineno , elineno + 1 ))
189
198
elif toktype == token .NEWLINE :
190
- if first_line is not None and elineno != first_line : # type: ignore[unreachable]
199
+ if first_line and elineno != first_line :
191
200
# We're at the end of a line, and we've ended on a
192
201
# different line than the first line of the statement,
193
202
# so record a multi-line range.
194
- for l in range (first_line , elineno + 1 ): # type: ignore[unreachable]
203
+ for l in range (first_line , elineno + 1 ):
195
204
self ._multiline [l ] = first_line
196
- first_line = None
205
+ first_line = 0
197
206
first_on_line = True
198
207
199
208
if ttext .strip () and toktype != tokenize .COMMENT :
200
209
# A non-white-space token.
201
210
empty = False
202
- if first_line is None :
211
+ if not first_line :
203
212
# The token is not white space, and is the first in a statement.
204
213
first_line = slineno
205
214
# Check whether to end an excluded suite.
0 commit comments