MCPcopy Index your code
hub / github.com/python/mypy / add_token

Method add_token

mypy/stubdoc.py:187–364  ·  view source on GitHub ↗

Process next token from the token stream.

(self, token: tokenize.TokenInfo)

Source from the content-addressed store, hash-verified

185 self.signatures: list[FunctionSig] = []
186
187 def add_token(self, token: tokenize.TokenInfo) -> None:
188 """Process next token from the token stream."""
189 if (
190 token.type == tokenize.NAME
191 and token.string == self.function_name
192 and self.state[-1] == STATE_INIT
193 ):
194 self.state.append(STATE_FUNCTION_NAME)
195
196 elif (
197 token.type == tokenize.OP
198 and token.string == "("
199 and self.state[-1] == STATE_FUNCTION_NAME
200 ):
201 self.state.pop()
202 self.accumulator = ""
203 self.found = True
204 self.state.append(STATE_ARGUMENT_LIST)
205
206 elif self.state[-1] == STATE_FUNCTION_NAME:
207 # Reset state, function name not followed by '('.
208 self.state.pop()
209
210 elif (
211 token.type == tokenize.OP
212 and token.string in ("[", "(", "{")
213 and self.state[-1] != STATE_INIT
214 ):
215 self.accumulator += token.string
216 self.state.append(STATE_OPEN_BRACKET)
217
218 elif (
219 token.type == tokenize.OP
220 and token.string in ("]", ")", "}")
221 and self.state[-1] == STATE_OPEN_BRACKET
222 ):
223 self.accumulator += token.string
224 self.state.pop()
225
226 elif (
227 token.type == tokenize.OP
228 and token.string == ":"
229 and self.state[-1] == STATE_ARGUMENT_LIST
230 ):
231 self.arg_name = self.accumulator
232 self.accumulator = ""
233 self.state.append(STATE_ARGUMENT_TYPE)
234
235 elif (
236 token.type == tokenize.OP
237 and token.string == ":"
238 and self.state[-1] == STATE_ARGUMENT_TYPE
239 and self.accumulator == ""
240 ):
241 # We thought we were after the colon of an "arg_name: arg_type"
242 # stanza, so we were expecting an "arg_type" now. However, we ended
243 # up with "arg_name::" (with two colons). That's a C++ type name,
244 # not an argument name followed by a Python type. This function

Callers 1

infer_sig_from_docstringFunction · 0.95

Calls 10

resetMethod · 0.95
lenFunction · 0.85
is_valid_typeFunction · 0.85
ArgSigClass · 0.85
boolClass · 0.85
FunctionSigClass · 0.85
appendMethod · 0.80
stripMethod · 0.80
popMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected