本文整理汇总了Python中mypy.nodes.SymbolTable.get方法的典型用法代码示例。如果您正苦于以下问题:Python SymbolTable.get方法的具体用法?Python SymbolTable.get怎么用?Python SymbolTable.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_type_promotion
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import get [as 别名]
def add_type_promotion(info: TypeInfo, module_names: SymbolTable, options: Options) -> None:
"""Setup extra, ad-hoc subtyping relationships between classes (promotion).
This includes things like 'int' being compatible with 'float'.
"""
defn = info.defn
promote_target = None # type: Optional[Type]
for decorator in defn.decorators:
if isinstance(decorator, CallExpr):
analyzed = decorator.analyzed
if isinstance(analyzed, PromoteExpr):
# _promote class decorator (undocumented feature).
promote_target = analyzed.type
if not promote_target:
promotions = (TYPE_PROMOTIONS_PYTHON3 if options.python_version[0] >= 3
else TYPE_PROMOTIONS_PYTHON2)
if defn.fullname in promotions:
target_sym = module_names.get(promotions[defn.fullname])
# With test stubs, the target may not exist.
if target_sym:
target_info = target_sym.node
assert isinstance(target_info, TypeInfo)
promote_target = Instance(target_info, [])
defn.info._promote = promote_target
示例2: SemanticAnalyzer
# 需要导入模块: from mypy.nodes import SymbolTable [as 别名]
# 或者: from mypy.nodes.SymbolTable import get [as 别名]
#.........这里部分代码省略.........
self.type = None
def object_type(self):
sym = self.lookup_qualified("__builtins__.object", None)
return Instance(sym.node, [])
def is_instance_type(self, t):
return isinstance(t, Instance) and not (t).type.is_interface
def add_class_type_variables_to_symbol_table(self, info):
vars = info.type_vars
if vars != []:
self.class_tvars = SymbolTable()
for i in range(len(vars)):
self.add_type_var(self.class_tvars, vars[i], i + 1)
def visit_import(self, i):
if not self.check_import_at_toplevel(i):
return
for id, as_id in i.ids:
if as_id != id:
m = self.modules[id]
self.globals[as_id] = SymbolTableNode(MODULE_REF, m, self.cur_mod_id)
else:
base = id.split(".")[0]
m = self.modules[base]
self.globals[base] = SymbolTableNode(MODULE_REF, m, self.cur_mod_id)
def visit_import_from(self, i):
if not self.check_import_at_toplevel(i):
return
m = self.modules[i.id]
for id, as_id in i.names:
node = m.names.get(id, None)
if node:
self.globals[as_id] = SymbolTableNode(node.kind, node.node, self.cur_mod_id)
else:
self.fail("Module has no attribute '{}'".format(id), i)
def visit_import_all(self, i):
if not self.check_import_at_toplevel(i):
return
m = self.modules[i.id]
for name, node in m.names.items():
if not name.startswith("_"):
self.globals[name] = SymbolTableNode(node.kind, node.node, self.cur_mod_id)
def check_import_at_toplevel(self, c):
if self.block_depth > 0:
self.fail("Imports within blocks not supported yet", c)
return False
else:
return True
#
# Statements
#
def visit_block(self, b):
self.block_depth += 1
for s in b.body:
s.accept(self)
self.block_depth -= 1
def visit_block_maybe(self, b):
if b: