![](/img/trans.png)
[英]Making python code compatible for working with 2.7 and 3.6+ versions- regarding Queue module
[英]Make Python 3.6+ Code in 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 类型的注解。 它对运行时没有影响,可以删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.