MCPcopy Index your code
hub / github.com/python/cpython / is_soft_keyword_used

Function is_soft_keyword_used

Lib/_pyrepl/utils.py:233–286  ·  view source on GitHub ↗

Returns True if the current token is a keyword in this context. For the `*tokens` to match anything, they have to be a three-tuple of (previous, current, next).

(*tokens: TI | None)

Source from the content-addressed store, hash-verified

231
232
233def is_soft_keyword_used(*tokens: TI | None) -> bool:
234 """Returns True if the current token is a keyword in this context.
235
236 For the `*tokens` to match anything, they have to be a three-tuple of
237 (previous, current, next).
238 """
239 trace("is_soft_keyword_used{t}", t=tokens)
240 match tokens:
241 case (
242 None | TI(T.NEWLINE) | TI(T.INDENT) | TI(string=":"),
243 TI(string="match"),
244 TI(T.NUMBER | T.STRING | T.FSTRING_START | T.TSTRING_START)
245 | TI(T.OP, string="(" | "*" | "[" | "{" | "~" | "...")
246 ):
247 return True
248 case (
249 None | TI(T.NEWLINE) | TI(T.INDENT) | TI(string=":"),
250 TI(string="match"),
251 TI(T.NAME, string=s)
252 ):
253 if keyword.iskeyword(s):
254 return s in keyword_first_sets_match
255 return True
256 case (
257 None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":"),
258 TI(string="case"),
259 TI(T.NUMBER | T.STRING | T.FSTRING_START | T.TSTRING_START)
260 | TI(T.OP, string="(" | "*" | "-" | "[" | "{")
261 ):
262 return True
263 case (
264 None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":"),
265 TI(string="case"),
266 TI(T.NAME, string=s)
267 ):
268 if keyword.iskeyword(s):
269 return s in keyword_first_sets_case
270 return True
271 case (TI(string="case"), TI(string="_"), TI(string=":")):
272 return True
273 case (
274 None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":"),
275 TI(string="type"),
276 TI(T.NAME, string=s)
277 ):
278 return not keyword.iskeyword(s)
279 case (
280 None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":" | ";"),
281 TI(string="lazy"),
282 TI(string="import") | TI(string="from")
283 ):
284 return True
285 case _:
286 return False
287
288
289def disp_str(

Callers 1

Calls 1

traceFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…