在 Python 3.6+ 中编写代码与 Python 3.3 兼容

Make a Code in Python 3.6+ Compatible with Python 3.3

这是 Python 3.6 中的部分代码 (Parso):

class BaseParser:
"""Parser engine.
A Parser instance contains state pertaining to the current token
sequence, and should not be used concurrently by different threads
to parse separate token sequences.
See python/tokenize.py for how to get input tokens by a string.
When a syntax error occurs, error_recovery() is called.
"""

node_map: Dict[str, type] = {}
default_node = tree.Node

leaf_map: Dict[str, type] = {}
default_leaf = tree.Leaf

def __init__(self, pgen_grammar, start_nonterminal='file_input', error_recovery=False):
    self._pgen_grammar = pgen_grammar
    self._start_nonterminal = start_nonterminal
    self._error_recovery = error_recovery

如何让它与 Python 3.3 兼容? leaf_map: Dict[str, type] = {}有什么用?我可以删除它吗?

Dict[str, type] 是 python 类型注释。它对运行时没有影响,可以删除。

https://docs.python.org/3/library/typing.html