本文整理汇总了Python中mypy.nodes.Node.accept方法的典型用法代码示例。如果您正苦于以下问题:Python Node.accept方法的具体用法?Python Node.accept怎么用?Python Node.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.Node
的用法示例。
在下文中一共展示了Node.accept方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_dependencies_of_target
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def get_dependencies_of_target(module_id: str,
module_tree: MypyFile,
target: Node,
type_map: Dict[Expression, Type],
python_version: Tuple[int, int]) -> Dict[str, Set[str]]:
"""Get dependencies of a target -- don't recursive into nested targets."""
# TODO: Add tests for this function.
visitor = DependencyVisitor(type_map, python_version, module_tree.alias_deps)
visitor.scope.enter_file(module_id)
if isinstance(target, MypyFile):
# Only get dependencies of the top-level of the module. Don't recurse into
# functions.
for defn in target.defs:
# TODO: Recurse into top-level statements and class bodies but skip functions.
if not isinstance(defn, (ClassDef, Decorator, FuncDef, OverloadedFuncDef)):
defn.accept(visitor)
elif isinstance(target, FuncBase) and target.info:
# It's a method.
# TODO: Methods in nested classes.
visitor.scope.enter_class(target.info)
target.accept(visitor)
visitor.scope.leave()
else:
target.accept(visitor)
visitor.scope.leave()
return visitor.map
示例2: find_classes
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def find_classes(node: Node) -> Set[str]:
results = set() # type: Set[str]
class ClassTraverser(mypy.traverser.TraverserVisitor):
def visit_class_def(self, o: ClassDef) -> None:
results.add(o.name)
node.accept(ClassTraverser())
return results
示例3: generate_html_report
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def generate_html_report(tree: Node, path: str, type_map: Dict[Node, Type],
output_dir: str) -> None:
if is_special_module(path):
return
# There may be more than one right answer for "what should we do here?"
# but this is a reasonable one.
path = os.path.relpath(path)
if path.startswith('..'):
return
visitor = StatisticsVisitor(inferred=True, typemap=type_map, all_nodes=True)
tree.accept(visitor)
assert not os.path.isabs(path) and not path.startswith('..')
# This line is *wrong* if the preceding assert fails.
target_path = os.path.join(output_dir, 'html', path)
# replace .py or .pyi with .html
target_path = os.path.splitext(target_path)[0] + '.html'
assert target_path.endswith('.html')
ensure_dir_exists(os.path.dirname(target_path))
output = [] # type: List[str]
append = output.append
append('''\
<html>
<head>
<style>
.red { background-color: #faa; }
.yellow { background-color: #ffa; }
.white { }
.lineno { color: #999; }
</style>
</head>
<body>
<pre>''')
num_imprecise_lines = 0
num_lines = 0
with open(path) as input_file:
for i, line in enumerate(input_file):
lineno = i + 1
status = visitor.line_map.get(lineno, TYPE_PRECISE)
style_map = {TYPE_PRECISE: 'white',
TYPE_IMPRECISE: 'yellow',
TYPE_ANY: 'red'}
style = style_map[status]
append('<span class="lineno">%4d</span> ' % lineno +
'<span class="%s">%s</span>' % (style,
cgi.escape(line)))
if status != TYPE_PRECISE:
num_imprecise_lines += 1
if line.strip():
num_lines += 1
append('</pre>')
append('</body></html>')
with open(target_path, 'w') as output_file:
output_file.writelines(output)
target_path = target_path[len(output_dir) + 1:]
html_files.append((path, target_path, num_lines, num_imprecise_lines))
示例4: generate_html_report
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def generate_html_report(tree: Node, path: str, type_map: Dict[Node, Type],
output_dir: str) -> None:
if is_special_module(path):
return
visitor = StatisticsVisitor(inferred=True, typemap=type_map, all_nodes=True)
tree.accept(visitor)
target_path = os.path.join(output_dir, 'html', path)
target_path = re.sub(r'\.py$', '.html', target_path)
ensure_dir_exists(os.path.dirname(target_path))
output = [] # type: List[str]
append = output.append
append('''\
<html>
<head>
<style>
.red { background-color: #faa; }
.yellow { background-color: #ffa; }
.white { }
.lineno { color: #999; }
</style>
</head>
<body>
<pre>''')
num_imprecise_lines = 0
num_lines = 0
with open(path) as input_file:
for i, line in enumerate(input_file):
lineno = i + 1
status = visitor.line_map.get(lineno, TYPE_PRECISE)
style_map = { TYPE_PRECISE: 'white',
TYPE_IMPRECISE: 'yellow',
TYPE_ANY: 'red' }
style = style_map[status]
append('<span class="lineno">%4d</span> ' % lineno +
'<span class="%s">%s</span>' % (style,
cgi.escape(line)))
if status != TYPE_PRECISE:
num_imprecise_lines += 1
if line.strip():
num_lines += 1
append('</pre>')
append('</body></html>')
with open(target_path, 'w') as output_file:
output_file.writelines(output)
target_path = target_path[len(output_dir) + 1:]
html_files.append((path, target_path, num_lines, num_imprecise_lines))
示例5: dump_type_stats
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def dump_type_stats(tree: Node, path: str, inferred: bool = False, typemap: Dict[Node, Type] = None) -> None:
if is_special_module(path):
return
print(path)
visitor = StatisticsVisitor(inferred, typemap)
tree.accept(visitor)
for line in visitor.output:
print(line)
print(" ** precision **")
print(" precise ", visitor.num_precise)
print(" imprecise", visitor.num_imprecise)
print(" any ", visitor.num_any)
print(" ** kinds **")
print(" simple ", visitor.num_simple)
print(" generic ", visitor.num_generic)
print(" function ", visitor.num_function)
print(" tuple ", visitor.num_tuple)
print(" typevar ", visitor.num_typevar)
print(" complex ", visitor.num_complex)
print(" any ", visitor.num_any)
示例6: dump_type_stats
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def dump_type_stats(tree: Node, path: str, inferred: bool = False,
typemap: Dict[Node, Type] = None) -> None:
if is_special_module(path):
return
print(path)
visitor = StatisticsVisitor(inferred, typemap)
tree.accept(visitor)
for line in visitor.output:
print(line)
print(' ** precision **')
print(' precise ', visitor.num_precise)
print(' imprecise', visitor.num_imprecise)
print(' any ', visitor.num_any)
print(' ** kinds **')
print(' simple ', visitor.num_simple)
print(' generic ', visitor.num_generic)
print(' function ', visitor.num_function)
print(' tuple ', visitor.num_tuple)
print(' TypeVar ', visitor.num_typevar)
print(' complex ', visitor.num_complex)
print(' any ', visitor.num_any)
示例7: node
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def node(self, n: Node) -> None:
n.accept(self)
示例8: node
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def node(self, node: Node) -> Node:
new = node.accept(self)
new.set_line(node.line)
return new
示例9: accept
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def accept(self, node: Node) -> None:
try:
node.accept(self)
except Exception as err:
report_internal_error(err, self.errors.file, node.line, self.errors, self.options)
示例10: accept
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def accept(self, n: Node, target: int = -1) -> int:
self.targets.append(target)
actual = n.accept(self)
self.targets.pop()
return actual
示例11: get_subexpressions
# 需要导入模块: from mypy.nodes import Node [as 别名]
# 或者: from mypy.nodes.Node import accept [as 别名]
def get_subexpressions(node: Node) -> List[Expression]:
visitor = SubexpressionFinder()
node.accept(visitor)
return visitor.expressions