当前位置: 首页>>代码示例>>Python>>正文


Python ClassDef.type_vars方法代码示例

本文整理汇总了Python中mypy.nodes.ClassDef.type_vars方法的典型用法代码示例。如果您正苦于以下问题:Python ClassDef.type_vars方法的具体用法?Python ClassDef.type_vars怎么用?Python ClassDef.type_vars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mypy.nodes.ClassDef的用法示例。


在下文中一共展示了ClassDef.type_vars方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_type_info

# 需要导入模块: from mypy.nodes import ClassDef [as 别名]
# 或者: from mypy.nodes.ClassDef import type_vars [as 别名]
def make_type_info(name: str,
                   is_abstract: bool = False,
                   mro: List[TypeInfo] = None,
                   bases: List[Instance] = None,
                   typevars: List[str] = None) -> TypeInfo:
    """Make a TypeInfo suitable for use in unit tests."""

    class_def = ClassDef(name, Block([]), None, [])
    class_def.fullname = name

    if typevars:
        v = []  # type: List[TypeVarDef]
        id = 1
        for n in typevars:
            v.append(TypeVarDef(n, id, None))
            id += 1
        class_def.type_vars = v

    info = TypeInfo(SymbolTable(), class_def)
    if mro is None:
        mro = []
    info.mro = [info] + mro
    if bases is None:
        if mro:
            # By default, assume that there is a single non-generic base.
            bases = [Instance(mro[0], [])]
        else:
            bases = []
    info.bases = bases

    return info
开发者ID:akaihola,项目名称:mypy,代码行数:33,代码来源:typefixture.py

示例2: visit_class_def

# 需要导入模块: from mypy.nodes import ClassDef [as 别名]
# 或者: from mypy.nodes.ClassDef import type_vars [as 别名]
    def visit_class_def(self, node: ClassDef) -> None:
        """Strip class body and type info, but don't strip methods."""
        to_delete = set(self.strip_type_info(node.info))
        node.type_vars = []
        node.base_type_exprs.extend(node.removed_base_type_exprs)
        node.removed_base_type_exprs = []
        node.defs.body = [s for s in node.defs.body
                          if s not in to_delete]

        with self.enter_class(node.info):
            super().visit_class_def(node)
开发者ID:Michael0x2a,项目名称:mypy,代码行数:13,代码来源:aststrip.py

示例3: make_type_info

# 需要导入模块: from mypy.nodes import ClassDef [as 别名]
# 或者: from mypy.nodes.ClassDef import type_vars [as 别名]
    def make_type_info(self, name: str,
                       module_name: Optional[str] = None,
                       is_abstract: bool = False,
                       mro: Optional[List[TypeInfo]] = None,
                       bases: Optional[List[Instance]] = None,
                       typevars: Optional[List[str]] = None,
                       variances: Optional[List[int]] = None) -> TypeInfo:
        """Make a TypeInfo suitable for use in unit tests."""

        class_def = ClassDef(name, Block([]), None, [])
        class_def.fullname = name

        if module_name is None:
            if '.' in name:
                module_name = name.rsplit('.', 1)[0]
            else:
                module_name = '__main__'

        if typevars:
            v = []  # type: List[TypeVarDef]
            for id, n in enumerate(typevars, 1):
                if variances:
                    variance = variances[id - 1]
                else:
                    variance = COVARIANT
                v.append(TypeVarDef(n, n, id, [], self.o, variance=variance))
            class_def.type_vars = v

        info = TypeInfo(SymbolTable(), class_def, module_name)
        if mro is None:
            mro = []
            if name != 'builtins.object':
                mro.append(self.oi)
        info.mro = [info] + mro
        if bases is None:
            if mro:
                # By default, assume that there is a single non-generic base.
                bases = [Instance(mro[0], [])]
            else:
                bases = []
        info.bases = bases

        return info
开发者ID:python,项目名称:mypy,代码行数:45,代码来源:typefixture.py

示例4: visit_class_def

# 需要导入模块: from mypy.nodes import ClassDef [as 别名]
# 或者: from mypy.nodes.ClassDef import type_vars [as 别名]
 def visit_class_def(self, node: ClassDef) -> None:
     """Strip class body and type info, but don't strip methods."""
     # We need to save the implicitly defined instance variables,
     # i.e. those defined as attributes on self. Otherwise, they would
     # be lost if we only reprocess top-levels (this kills TypeInfos)
     # but not the methods that defined those variables.
     if not self.recurse_into_functions:
         self.prepare_implicit_var_patches(node)
     # We need to delete any entries that were generated by plugins,
     # since they will get regenerated.
     to_delete = {v.node for v in node.info.names.values() if v.plugin_generated}
     node.type_vars = []
     node.base_type_exprs.extend(node.removed_base_type_exprs)
     node.removed_base_type_exprs = []
     node.defs.body = [s for s in node.defs.body
                       if s not in to_delete]
     with self.enter_class(node.info):
         super().visit_class_def(node)
     TypeState.reset_subtype_caches_for(node.info)
     # Kill the TypeInfo, since there is none before semantic analysis.
     node.info = CLASSDEF_NO_INFO
开发者ID:elazarg,项目名称:mypy,代码行数:23,代码来源:aststripnew.py


注:本文中的mypy.nodes.ClassDef.type_vars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。