本文整理汇总了Python中mypy.nodes.MypyFile.fullname方法的典型用法代码示例。如果您正苦于以下问题:Python MypyFile.fullname方法的具体用法?Python MypyFile.fullname怎么用?Python MypyFile.fullname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.MypyFile
的用法示例。
在下文中一共展示了MypyFile.fullname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge_asts
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def merge_asts(old: MypyFile, old_symbols: SymbolTable,
new: MypyFile, new_symbols: SymbolTable) -> None:
"""Merge a new version of a module AST to a previous version.
The main idea is to preserve the identities of externally visible
nodes in the old AST (that have a corresponding node in the new AST).
All old node state (outside identity) will come from the new AST.
When this returns, 'old' will refer to the merged AST, but 'new_symbols'
will be the new symbol table. 'new' and 'old_symbols' will no longer be
valid.
"""
assert new.fullname() == old.fullname()
# Find the mapping from new to old node identities for all nodes
# whose identities should be preserved.
replacement_map = replacement_map_from_symbol_table(
old_symbols, new_symbols, prefix=old.fullname())
# Also replace references to the new MypyFile node.
replacement_map[new] = old
# Perform replacements to everywhere within the new AST (not including symbol
# tables).
node = replace_nodes_in_ast(new, replacement_map)
assert node is old
# Also replace AST node references in the *new* symbol table (we'll
# continue to use the new symbol table since it has all the new definitions
# that have no correspondence in the old AST).
replace_nodes_in_symbol_table(new_symbols, replacement_map)
示例2: get_python_out_path
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def get_python_out_path(self, f: MypyFile) -> str:
if f.fullname() == '__main__':
return os.path.join(self.output_dir, basename(f.path))
else:
components = f.fullname().split('.')
if os.path.basename(f.path) == '__init__.py':
components.append('__init__.py')
else:
components[-1] += '.py'
return os.path.join(self.output_dir, *components)
示例3: visit_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def visit_file(self, file_node: MypyFile, fnam: str, options: Options,
patches: List[Callable[[], None]]) -> None:
self.recurse_into_functions = True
self.errors.set_file(fnam, file_node.fullname())
self.options = options
self.sem.options = options
self.patches = patches
self.is_typeshed_file = self.errors.is_typeshed_file(fnam)
self.sem.cur_mod_id = file_node.fullname()
self.sem.globals = file_node.names
with experiments.strict_optional_set(options.strict_optional):
self.accept(file_node)
示例4: on_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def on_file(self,
tree: MypyFile,
type_map: Dict[Expression, Type],
options: Options) -> None:
visitor = stats.StatisticsVisitor(inferred=True, filename=tree.fullname(),
typemap=type_map, all_nodes=True,
visit_untyped_defs=False)
tree.accept(visitor)
self.any_types_counter[tree.fullname()] = visitor.type_of_any_counter
num_unanalyzed_lines = list(visitor.line_map.values()).count(stats.TYPE_UNANALYZED)
# count each line of dead code as one expression of type "Any"
num_any = visitor.num_any_exprs + num_unanalyzed_lines
num_total = visitor.num_imprecise_exprs + visitor.num_precise_exprs + num_any
if num_total > 0:
self.counts[tree.fullname()] = (num_any, num_total)
示例5: visit_mypy_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def visit_mypy_file(self, mfile: MypyFile) -> int:
if mfile.fullname() in ('typing', 'abc'):
# These module are special; their contents are currently all
# built-in primitives.
return -1
self.enter()
# Initialize non-int global variables.
for name in sorted(mfile.names):
node = mfile.names[name].node
if (isinstance(node, Var) and
name not in nodes.implicit_module_attrs):
v = cast(Var, node)
if (not is_named_instance(v.type, 'builtins.int')
and v.fullname() != 'typing.Undefined'):
tmp = self.alloc_register()
self.add(SetRNone(tmp))
self.add(SetGR(v.fullname(), tmp))
for d in mfile.defs:
d.accept(self)
self.add_implicit_return()
self.generated['__init'] = FuncIcode(0, self.blocks,
self.register_types)
# TODO leave?
return -1
示例6: visit_mypy_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def visit_mypy_file(self, o: MypyFile) -> None:
self.scope.enter_file(o.fullname())
self.is_package_init_file = o.is_package_init_file()
self.add_type_alias_deps(self.scope.current_target())
for trigger, targets in o.plugin_deps.items():
self.map.setdefault(trigger, set()).update(targets)
super().visit_mypy_file(o)
self.scope.leave()
示例7: visit_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def visit_file(self, file_node: MypyFile, fnam: str, options: Options,
patches: List[Tuple[int, Callable[[], None]]]) -> None:
self.recurse_into_functions = True
self.errors.set_file(fnam, file_node.fullname(), scope=self.scope)
self.options = options
self.sem.options = options
self.patches = patches
self.is_typeshed_file = self.errors.is_typeshed_file(fnam)
self.sem.cur_mod_id = file_node.fullname()
self.cur_mod_node = file_node
self.sem.globals = file_node.names
with experiments.strict_optional_set(options.strict_optional):
self.scope.enter_file(file_node.fullname())
self.accept(file_node)
self.analyze_symbol_table(file_node.names)
self.scope.leave()
del self.cur_mod_node
self.patches = []
示例8: visit_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def visit_file(self, file_node: MypyFile, fnam: str, options: Options,
patches: List[Tuple[int, Callable[[], None]]]) -> None:
self.recurse_into_functions = True
self.options = options
self.sem.options = options
self.patches = patches
self.is_typeshed_file = self.errors.is_typeshed_file(fnam)
self.sem.cur_mod_id = file_node.fullname()
self.cur_mod_node = file_node
self.sem.globals = file_node.names
示例9: create_indirect_imported_name
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def create_indirect_imported_name(file_node: MypyFile,
module: str,
relative: int,
imported_name: str) -> Optional[SymbolTableNode]:
"""Create symbol table entry for a name imported from another module.
These entries act as indirect references.
"""
target_module, ok = correct_relative_import(
file_node.fullname(),
relative,
module,
file_node.is_package_init_file())
if not ok:
return None
target_name = '%s.%s' % (target_module, imported_name)
link = ImportedName(target_name)
# Use GDEF since this refers to a module-level definition.
return SymbolTableNode(GDEF, link)
示例10: dump_type_stats
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def dump_type_stats(tree: MypyFile, path: str, inferred: bool = False,
typemap: Optional[Dict[Expression, Type]] = None) -> None:
if is_special_module(path):
return
print(path)
visitor = StatisticsVisitor(inferred, filename=tree.fullname(), typemap=typemap)
tree.accept(visitor)
for line in visitor.output:
print(line)
print(' ** precision **')
print(' precise ', visitor.num_precise_exprs)
print(' imprecise', visitor.num_imprecise_exprs)
print(' any ', visitor.num_any_exprs)
print(' ** kinds **')
print(' simple ', visitor.num_simple_types)
print(' generic ', visitor.num_generic_types)
print(' function ', visitor.num_function_types)
print(' tuple ', visitor.num_tuple_types)
print(' TypeVar ', visitor.num_typevar_types)
print(' complex ', visitor.num_complex_types)
print(' any ', visitor.num_any_types)
示例11: visit_mypy_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def visit_mypy_file(self, f: MypyFile) -> None:
self.is_typing = f.fullname() == 'typing' or f.fullname() == 'builtins'
super().visit_mypy_file(f)
示例12: get_additional_deps
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def get_additional_deps(self, file: MypyFile) -> List[Tuple[int, str, int]]:
if file.fullname() == '__main__':
return [(10, 'err', -1)]
return []
示例13: visit_mypy_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def visit_mypy_file(self, o: MypyFile) -> None:
self.errors.set_file(o.path, o.fullname(), scope=self.scope)
self.scope.enter_file(o.fullname())
super().visit_mypy_file(o)
self.scope.leave()
示例14: visit_mypy_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def visit_mypy_file(self, o: MypyFile) -> None:
self.scope.enter_file(o.fullname())
self.is_package_init_file = o.is_package_init_file()
self.add_type_alias_deps(self.scope.current_target())
super().visit_mypy_file(o)
self.scope.leave()
示例15: visit_mypy_file
# 需要导入模块: from mypy.nodes import MypyFile [as 别名]
# 或者: from mypy.nodes.MypyFile import fullname [as 别名]
def visit_mypy_file(self, o: MypyFile) -> None:
self.enter_file_scope(o.fullname())
super().visit_mypy_file(o)
self.leave_scope()