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)
| 231 | |
| 232 | |
| 233 | def 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 | |
| 289 | def disp_str( |
no test coverage detected
searching dependent graphs…