當前位置: 首頁>>代碼示例>>Python>>正文


Python SymbolTable.get方法代碼示例

本文整理匯總了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
開發者ID:Michael0x2a,項目名稱:mypy,代碼行數:26,代碼來源:semanal_classprop.py

示例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:
開發者ID:SRiikonen,項目名稱:mypy-py,代碼行數:70,代碼來源:semanal.py


注:本文中的mypy.nodes.SymbolTable.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。