本文整理汇总了Python中mypy.nodes.SymbolTable.items方法的典型用法代码示例。如果您正苦于以下问题:Python SymbolTable.items方法的具体用法?Python SymbolTable.items怎么用?Python SymbolTable.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.items方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compute_all_mros
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def compute_all_mros(symtab: SymbolTable, modules: Dict[str, MypyFile]) -> None:
for key, value in symtab.items():
if value.kind in (LDEF, MDEF, GDEF) and isinstance(value.node, TypeInfo):
info = value.node
info.calculate_mro()
assert info.mro, "No MRO calculated for %s" % (info.fullname(),)
compute_all_mros(info.names, modules)
示例2: replacement_map_from_symbol_table
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def replacement_map_from_symbol_table(
old: SymbolTable, new: SymbolTable, prefix: str) -> Dict[SymbolNode, SymbolNode]:
"""Create a new-to-old object identity map by comparing two symbol table revisions.
Both symbol tables must refer to revisions of the same module id. The symbol tables
are compared recursively (recursing into nested class symbol tables), but only within
the given module prefix. Don't recurse into other modules accessible through the symbol
table.
"""
replacements = {} # type: Dict[SymbolNode, SymbolNode]
for name, node in old.items():
if (name in new and (node.kind == MDEF
or node.node and get_prefix(node.node.fullname()) == prefix)):
new_node = new[name]
if (type(new_node.node) == type(node.node) # noqa
and new_node.node and node.node and
new_node.node.fullname() == node.node.fullname() and
new_node.kind == node.kind):
replacements[new_node.node] = node.node
if isinstance(node.node, TypeInfo) and isinstance(new_node.node, TypeInfo):
type_repl = replacement_map_from_symbol_table(
node.node.names,
new_node.node.names,
prefix)
replacements.update(type_repl)
return replacements
示例3: visit_symbol_table
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def visit_symbol_table(self, symtab: SymbolTable) -> None:
# Copy the items because we may mutate symtab.
for key, value in list(symtab.items()):
cross_ref = value.cross_ref
if cross_ref is not None: # Fix up cross-reference.
del value.cross_ref
if cross_ref in self.modules:
value.node = self.modules[cross_ref]
else:
stnode = lookup_qualified_stnode(self.modules, cross_ref,
self.quick_and_dirty)
if stnode is not None:
value.node = stnode.node
value.type_override = stnode.type_override
if (self.quick_and_dirty and value.kind == TYPE_ALIAS and
stnode.type_override is None):
value.type_override = Instance(stale_info(self.modules), [])
value.alias_tvars = stnode.alias_tvars or []
elif not self.quick_and_dirty:
assert stnode is not None, "Could not find cross-ref %s" % (cross_ref,)
else:
# We have a missing crossref in quick mode, need to put something
value.node = stale_info(self.modules)
if value.kind == TYPE_ALIAS:
value.type_override = Instance(stale_info(self.modules), [])
else:
if isinstance(value.node, TypeInfo):
# TypeInfo has no accept(). TODO: Add it?
self.visit_type_info(value.node)
elif value.node is not None:
value.node.accept(self)
if value.type_override is not None:
value.type_override.accept(self.type_fixer)
示例4: dump_typeinfos_recursive
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def dump_typeinfos_recursive(self, names: SymbolTable) -> List[str]:
a = []
for name, node in sorted(names.items(), key=lambda x: x[0]):
if isinstance(node.node, TypeInfo):
a.extend(self.dump_typeinfo(node.node))
a.extend(self.dump_typeinfos_recursive(node.node.names))
return a
示例5: replace_nodes_in_symbol_table
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def replace_nodes_in_symbol_table(symbols: SymbolTable,
replacements: Dict[SymbolNode, SymbolNode]) -> None:
for name, node in symbols.items():
if node.node:
if node.node in replacements:
new = replacements[node.node]
old = node.node
replace_object_state(new, old)
node.node = new
if isinstance(node.node, Var):
# Handle them here just in case these aren't exposed through the AST.
# TODO: Is this necessary?
fixup_var(node.node, replacements)
示例6: find_symbol_tables_recursive
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def find_symbol_tables_recursive(prefix: str, symbols: SymbolTable) -> Dict[str, SymbolTable]:
"""Find all nested symbol tables.
Args:
prefix: Full name prefix (used for return value keys and to filter result so that
cross references to other modules aren't included)
symbols: Root symbol table
Returns a dictionary from full name to corresponding symbol table.
"""
result = {}
result[prefix] = symbols
for name, node in symbols.items():
if isinstance(node.node, TypeInfo) and node.node.fullname().startswith(prefix + '.'):
more = find_symbol_tables_recursive(prefix + '.' + name, node.node.names)
result.update(more)
return result
示例7: replacement_map_from_symbol_table
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def replacement_map_from_symbol_table(
old: SymbolTable, new: SymbolTable, prefix: str) -> Dict[SymbolNode, SymbolNode]:
replacements = {} # type: Dict[SymbolNode, SymbolNode]
for name, node in old.items():
if (name in new and (node.kind == MDEF
or node.node and get_prefix(node.node.fullname()) == prefix)):
new_node = new[name]
if (type(new_node.node) == type(node.node) # noqa
and new_node.node and node.node and
new_node.node.fullname() == node.node.fullname() and
new_node.kind == node.kind):
replacements[new_node.node] = node.node
if isinstance(node.node, TypeInfo) and isinstance(new_node.node, TypeInfo):
type_repl = replacement_map_from_symbol_table(
node.node.names,
new_node.node.names,
prefix)
replacements.update(type_repl)
return replacements
示例8: snapshot_symbol_table
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def snapshot_symbol_table(name_prefix: str, table: SymbolTable) -> Dict[str, SnapshotItem]:
"""Create a snapshot description that represents the state of a symbol table.
The snapshot has a representation based on nested tuples and dicts
that makes it easy and fast to find differences.
Only "shallow" state is included in the snapshot -- references to
things defined in other modules are represented just by the names of
the targets.
"""
result = {} # type: Dict[str, SnapshotItem]
for name, symbol in table.items():
node = symbol.node
# TODO: cross_ref?
fullname = node.fullname() if node else None
common = (fullname, symbol.kind, symbol.module_public)
if symbol.kind == MODULE_REF:
# This is a cross-reference to another module.
# If the reference is busted because the other module is missing,
# the node will be a "stale_info" TypeInfo produced by fixup,
# but that doesn't really matter to us here.
result[name] = ('Moduleref', common)
elif symbol.kind == TVAR:
assert isinstance(node, TypeVarExpr)
result[name] = ('TypeVar',
node.variance,
[snapshot_type(value) for value in node.values],
snapshot_type(node.upper_bound))
elif isinstance(symbol.node, TypeAlias):
result[name] = ('TypeAlias',
symbol.node.alias_tvars,
symbol.node.normalized,
symbol.node.no_args,
snapshot_optional_type(symbol.node.target))
else:
assert symbol.kind != UNBOUND_IMPORTED
if node and get_prefix(node.fullname()) != name_prefix:
# This is a cross-reference to a node defined in another module.
result[name] = ('CrossRef', common)
else:
result[name] = snapshot_definition(node, common)
return result
示例9: replace_nodes_in_symbol_table
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def replace_nodes_in_symbol_table(symbols: SymbolTable,
replacements: Dict[SymbolNode, SymbolNode]) -> None:
for name, node in symbols.items():
if node.node:
if node.node in replacements:
new = replacements[node.node]
new.__dict__ = node.node.__dict__
node.node = new
# TODO: Other node types
if isinstance(node.node, Var) and node.node.type:
node.node.type.accept(TypeReplaceVisitor(replacements))
node.node.info = cast(TypeInfo, replacements.get(node.node.info,
node.node.info))
else:
# TODO: Other node types
if isinstance(node.node, Var) and node.node.type:
node.node.type.accept(TypeReplaceVisitor(replacements))
override = node.type_override
if override:
override.accept(TypeReplaceVisitor(replacements))
示例10: visit_symbol_table
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def visit_symbol_table(self, symtab: SymbolTable) -> None:
# Copy the items because we may mutate symtab.
for key, value in list(symtab.items()):
cross_ref = value.cross_ref
if cross_ref is not None: # Fix up cross-reference.
del value.cross_ref
if cross_ref in self.modules:
value.node = self.modules[cross_ref]
else:
stnode = lookup_qualified_stnode(self.modules, cross_ref)
assert stnode is not None, "Could not find cross-ref %s" % (cross_ref,)
value.node = stnode.node
value.type_override = stnode.type_override
else:
if isinstance(value.node, TypeInfo):
# TypeInfo has no accept(). TODO: Add it?
self.visit_type_info(value.node)
elif value.node is not None:
value.node.accept(self)
if value.type_override is not None:
value.type_override.accept(self.type_fixer)
示例11: visit_symbol_table
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import items [as 别名]
def visit_symbol_table(self, symtab: SymbolTable) -> None:
# Copy the items because we may mutate symtab.
for key, value in list(symtab.items()):
cross_ref = value.cross_ref
if cross_ref is not None: # Fix up cross-reference.
value.cross_ref = None
if cross_ref in self.modules:
value.node = self.modules[cross_ref]
else:
stnode = lookup_qualified_stnode(self.modules, cross_ref,
self.allow_missing)
if stnode is not None:
value.node = stnode.node
elif not self.allow_missing:
assert stnode is not None, "Could not find cross-ref %s" % (cross_ref,)
else:
# We have a missing crossref in allow missing mode, need to put something
value.node = missing_info(self.modules)
else:
if isinstance(value.node, TypeInfo):
# TypeInfo has no accept(). TODO: Add it?
self.visit_type_info(value.node)
elif value.node is not None:
value.node.accept(self)