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


Python TypeInfo.fullname方法代码示例

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


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

示例1: process_type_info

# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import fullname [as 别名]
 def process_type_info(self, info: TypeInfo) -> None:
     target = self.scope.current_full_target()
     for base in info.bases:
         self.add_type_dependencies(base, target=target)
     if info.tuple_type:
         self.add_type_dependencies(info.tuple_type, target=make_trigger(target))
     if info.typeddict_type:
         self.add_type_dependencies(info.typeddict_type, target=make_trigger(target))
     if info.declared_metaclass:
         self.add_type_dependencies(info.declared_metaclass, target=make_trigger(target))
     self.add_type_alias_deps(self.scope.current_target())
     for name, node in info.names.items():
         if isinstance(node.node, Var):
             for base_info in non_trivial_bases(info):
                 # If the type of an attribute changes in a base class, we make references
                 # to the attribute in the subclass stale.
                 self.add_dependency(make_trigger(base_info.fullname() + '.' + name),
                                     target=make_trigger(info.fullname() + '.' + name))
     for base_info in non_trivial_bases(info):
         for name, node in base_info.names.items():
             self.add_dependency(make_trigger(base_info.fullname() + '.' + name),
                                 target=make_trigger(info.fullname() + '.' + name))
         self.add_dependency(make_trigger(base_info.fullname() + '.__init__'),
                             target=make_trigger(info.fullname() + '.__init__'))
         self.add_dependency(make_trigger(base_info.fullname() + '.__new__'),
                             target=make_trigger(info.fullname() + '.__new__'))
开发者ID:sixolet,项目名称:mypy,代码行数:28,代码来源:deps.py

示例2: record_protocol_subtype_check

# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import fullname [as 别名]
 def record_protocol_subtype_check(left_type: TypeInfo, right_type: TypeInfo) -> None:
     assert right_type.is_protocol
     TypeState._rechecked_types.add(left_type)
     TypeState._attempted_protocols.setdefault(
         left_type.fullname(), set()).add(right_type.fullname())
     TypeState._checked_against_members.setdefault(
         left_type.fullname(),
         set()).update(right_type.protocol_members)
开发者ID:Michael0x2a,项目名称:mypy,代码行数:10,代码来源:typestate.py

示例3: dump_typeinfo

# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import fullname [as 别名]
 def dump_typeinfo(self, info: TypeInfo) -> List[str]:
     if info.fullname() == 'enum.Enum':
         # Avoid noise
         return []
     s = info.dump(str_conv=self.str_conv,
                   type_str_conv=self.type_str_conv)
     return s.splitlines()
开发者ID:Michael0x2a,项目名称:mypy,代码行数:9,代码来源:testmerge.py

示例4: linearize_hierarchy

# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import fullname [as 别名]
def linearize_hierarchy(info: TypeInfo,
                        obj_type: Optional[Callable[[], Instance]] = None) -> List[TypeInfo]:
    # TODO describe
    if info.mro:
        return info.mro
    bases = info.direct_base_classes()
    if (not bases and info.fullname() != 'builtins.object' and
            obj_type is not None):
        # Second pass in import cycle, add a dummy `object` base class,
        # otherwise MRO calculation may spuriously fail.
        # MRO will be re-calculated for real in the third pass.
        bases = [obj_type().type]
    lin_bases = []
    for base in bases:
        assert base is not None, "Cannot linearize bases for %s %s" % (info.fullname(), bases)
        lin_bases.append(linearize_hierarchy(base, obj_type))
    lin_bases.append(bases)
    return [info] + merge(lin_bases)
开发者ID:Michael0x2a,项目名称:mypy,代码行数:20,代码来源:mro.py

示例5: calculate_class_abstract_status

# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import fullname [as 别名]
def calculate_class_abstract_status(typ: TypeInfo, is_stub_file: bool, errors: Errors) -> None:
    """Calculate abstract status of a class.

    Set is_abstract of the type to True if the type has an unimplemented
    abstract attribute.  Also compute a list of abstract attributes.
    Report error is required ABCMeta metaclass is missing.
    """
    concrete = set()  # type: Set[str]
    abstract = []  # type: List[str]
    abstract_in_this_class = []  # type: List[str]
    for base in typ.mro:
        for name, symnode in base.names.items():
            node = symnode.node
            if isinstance(node, OverloadedFuncDef):
                # Unwrap an overloaded function definition. We can just
                # check arbitrarily the first overload item. If the
                # different items have a different abstract status, there
                # should be an error reported elsewhere.
                func = node.items[0]  # type: Optional[Node]
            else:
                func = node
            if isinstance(func, Decorator):
                fdef = func.func
                if fdef.is_abstract and name not in concrete:
                    typ.is_abstract = True
                    abstract.append(name)
                    if base is typ:
                        abstract_in_this_class.append(name)
            elif isinstance(node, Var):
                if node.is_abstract_var and name not in concrete:
                    typ.is_abstract = True
                    abstract.append(name)
                    if base is typ:
                        abstract_in_this_class.append(name)
            concrete.add(name)
    # In stubs, abstract classes need to be explicitly marked because it is too
    # easy to accidentally leave a concrete class abstract by forgetting to
    # implement some methods.
    typ.abstract_attributes = sorted(abstract)
    if is_stub_file:
        if typ.declared_metaclass and typ.declared_metaclass.type.fullname() == 'abc.ABCMeta':
            return
        if typ.is_protocol:
            return
        if abstract and not abstract_in_this_class:
            def report(message: str, severity: str) -> None:
                errors.report(typ.line, typ.column, message, severity=severity)

            attrs = ", ".join('"{}"'.format(attr) for attr in sorted(abstract))
            report("Class {} has abstract attributes {}".format(typ.fullname(), attrs), 'error')
            report("If it is meant to be abstract, add 'abc.ABCMeta' as an explicit metaclass",
                   'note')
开发者ID:mananpal1997,项目名称:mypy,代码行数:54,代码来源:semanal_classprop.py

示例6: __init__

# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import fullname [as 别名]
 def __init__(self, type: TypeInfo, base: 'ClassRepresentation') -> None:
     self.cname = 'MR_%s' % type.name()
     self.fullname = type.fullname()
     self.slotmap = {}
     self.vtable_index = {}
     self.defining_class = {}
     self.vtable_methods = []
     if base:
         self.inherit_from_base(base)
     for m in sorted(type.names):
         if isinstance(type.names[m].node, FuncBase):
             self.add_method(m, type)
         else:
             self.slotmap[m] = len(self.slotmap)
             self.add_method('_' + m, type)    # Getter TODO refactor
             self.add_method('set_' + m, type) # Setter # TODO refactor
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:18,代码来源:cgen.py

示例7: generate_class

# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import fullname [as 别名]
    def generate_class(self, cls: TypeInfo) -> 'ClassRepresentation':
        if cls.bases:
            baserep = self.get_class_representation(cls.bases[0].type)
        else:
            baserep = None
        rep = ClassRepresentation(cls, baserep)
        self.classes[cls] = rep

        # Emit vtable.
        vtable = 'MVT_%s' % cls.name()
        self.emit_types('MFunction %s[] = {' % vtable)
        for m in rep.vtable_methods:
            defining_class = rep.defining_class[m]
            self.emit_types('    M%s_%s,' % (defining_class, m))
        self.emit_types('}; /* %s */' % vtable)

        # Emit type runtime info.
        self.emit_types('MTypeRepr %s = {' % rep.cname)
        self.emit_types('    %s,' % vtable)
        self.emit_types('    0,')
        self.emit_types('    "%s"' % cls.fullname())
        self.emit_types('};\n')
        
        return rep
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:26,代码来源:cgen.py

示例8: process_type_info

# 需要导入模块: from mypy.nodes import TypeInfo [as 别名]
# 或者: from mypy.nodes.TypeInfo import fullname [as 别名]
    def process_type_info(self, info: TypeInfo) -> None:
        target = self.scope.current_full_target()
        for base in info.bases:
            self.add_type_dependencies(base, target=target)
        if info.tuple_type:
            self.add_type_dependencies(info.tuple_type, target=make_trigger(target))
        if info.typeddict_type:
            self.add_type_dependencies(info.typeddict_type, target=make_trigger(target))
        if info.declared_metaclass:
            self.add_type_dependencies(info.declared_metaclass, target=make_trigger(target))
        if info.is_protocol:
            for base_info in info.mro[:-1]:
                # We add dependencies from whole MRO to cover explicit subprotocols.
                # For example:
                #
                #     class Super(Protocol):
                #         x: int
                #     class Sub(Super, Protocol):
                #         y: int
                #
                # In this example we add <Super[wildcard]> -> <Sub>, to invalidate Sub if
                # a new member is added to Super.
                self.add_dependency(make_wildcard_trigger(base_info.fullname()),
                                    target=make_trigger(target))
                # More protocol dependencies are collected in TypeState._snapshot_protocol_deps
                # after a full run or update is finished.

        self.add_type_alias_deps(self.scope.current_target())
        for name, node in info.names.items():
            if isinstance(node.node, Var):
                # Recheck Liskov if needed, self definitions are checked in the defining method
                if node.node.is_initialized_in_class and has_user_bases(info):
                    self.add_dependency(make_trigger(info.fullname() + '.' + name))
                for base_info in non_trivial_bases(info):
                    # If the type of an attribute changes in a base class, we make references
                    # to the attribute in the subclass stale.
                    self.add_dependency(make_trigger(base_info.fullname() + '.' + name),
                                        target=make_trigger(info.fullname() + '.' + name))
        for base_info in non_trivial_bases(info):
            for name, node in base_info.names.items():
                if self.use_logical_deps():
                    # Skip logical dependency if an attribute is not overridden. For example,
                    # in case of:
                    #     class Base:
                    #         x = 1
                    #         y = 2
                    #     class Sub(Base):
                    #         x = 3
                    # we skip <Base.y> -> <Child.y>, because even if `y` is unannotated it
                    # doesn't affect precision of Liskov checking.
                    if name not in info.names:
                        continue
                    # __init__ and __new__ can be overridden with different signatures, so no
                    # logical depedency.
                    if name in ('__init__', '__new__'):
                        continue
                self.add_dependency(make_trigger(base_info.fullname() + '.' + name),
                                    target=make_trigger(info.fullname() + '.' + name))
            if not self.use_logical_deps():
                # These dependencies are only useful for propagating changes --
                # they aren't logical dependencies since __init__ and __new__ can be
                # overridden with a different signature.
                self.add_dependency(make_trigger(base_info.fullname() + '.__init__'),
                                    target=make_trigger(info.fullname() + '.__init__'))
                self.add_dependency(make_trigger(base_info.fullname() + '.__new__'),
                                    target=make_trigger(info.fullname() + '.__new__'))
                # If the set of abstract attributes change, this may invalidate class
                # instantiation, or change the generated error message, since Python checks
                # class abstract status when creating an instance.
                #
                # TODO: We should probably add this dependency only from the __init__ of the
                #     current class, and independent of bases (to trigger changes in message
                #     wording, as errors may enumerate all abstract attributes).
                self.add_dependency(make_trigger(base_info.fullname() + '.(abstract)'),
                                    target=make_trigger(info.fullname() + '.__init__'))
                # If the base class abstract attributes change, subclass abstract
                # attributes need to be recalculated.
                self.add_dependency(make_trigger(base_info.fullname() + '.(abstract)'))
开发者ID:Michael0x2a,项目名称:mypy,代码行数:80,代码来源:deps.py


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