简体   繁体   English

使 Python 3.6+ 代码与 Python 3.3 兼容

[英]Make Python 3.6+ Code in Compatible with Python 3.3

Here is a part of code ( Parso ) in Python 3.6:这是 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

How can I make it compatible with Python 3.3?如何使其与 Python 3.3 兼容? What is the usage of leaf_map: Dict[str, type] = {} ? leaf_map: Dict[str, type] = {}的用途是什么? Can I remove it?我可以删除它吗?

Dict[str, type] is python type annotations. Dict[str, type]是 python 类型的注解。 It has no impact in runtime and can be removed.它对运行时没有影响,可以删除。

See https://docs.python.org/3/library/typing.html请参阅https://docs.python.org/3/library/typing.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM