Python Language Services: keyword
Module
- Docs:
keyword
— Testing for Python keywords - Source Code: cpython/Lib/keyword.py
__all__ = ["iskeyword", "issoftkeyword", "kwlist", "softkwlist"]
kwlist = [
'False',
'None',
'True',
# ......
'yield'
]
softkwlist = [
'_',
'case',
'match',
'type'
]
iskeyword = frozenset(kwlist).__contains__
issoftkeyword = frozenset(softkwlist).__contains__
Python 的 tokenizer 会把 keyword, 比方说 if
直接识别成 TokenInfo(type=NAME, string="if")
, 并不会涉及 keyword
这个 module.
Docs 上直接说了:
This module allows a Python program to determine if a string is a keyword or soft keyword.
… but this distinction is done at the parser level, not when tokenizing.
留下评论