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


Python MessageBuilder.signature_incompatible_with_supertype方法代码示例

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


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

示例1: TypeChecker

# 需要导入模块: from mypy.messages import MessageBuilder [as 别名]
# 或者: from mypy.messages.MessageBuilder import signature_incompatible_with_supertype [as 别名]

#.........这里部分代码省略.........
                    # TODO overloaded signatures
                    self.check_override(typ,
                                        original_type,
                                        defn.name(),
                                        base_method.info.name(),
                                        defn)
            
            # Also check interface implementations.
            for iface in base.interfaces:
                self.check_method_or_accessor_override_for_base(defn, iface)
            
            # We have to check that the member is compatible with all
            # supertypes due to the dynamic type. Otherwise we could first
            # override with dynamic and then with an arbitary type.
            self.check_method_or_accessor_override_for_base(defn, base.base)
    
    def check_override(self, override, original, name, supertype, node):
        """Check a method override with given signatures.

        Arguments:
          override:  The signature of the overriding method.
          original:  The signature of the original supertype method.
          name:      The name of the subtype. This and the next argument are
                     only used for generating error messages.
          supertype: The name of the supertype.
        """
        if (isinstance(override, Overloaded) or
                isinstance(original, Overloaded) or
                len((override).arg_types) !=
                    len((original).arg_types) or
                (override).min_args !=
                    (original).min_args):
            if not is_subtype(override, original):
                self.msg.signature_incompatible_with_supertype(
                    name, supertype, node)
            return
        else:
            # Give more detailed messages for the common case of both
            # signatures having the same number of arguments and no
            # intersection types.
            
            coverride = override
            coriginal = original
            
            for i in range(len(coverride.arg_types)):
                if not is_equivalent(coriginal.arg_types[i],
                                     coverride.arg_types[i]):
                    self.msg.argument_incompatible_with_supertype(
                        i + 1, name, supertype, node)
            
            if not is_subtype(coverride.ret_type, coriginal.ret_type):
                self.msg.return_type_incompatible_with_supertype(
                    name, supertype, node)
    
    def visit_type_def(self, defn):
        """Type check a type definition (class or interface)."""
        typ = self.lookup(defn.name, GDEF).node
        self.errors.set_type(defn.name, defn.is_interface)
        self.check_unique_interface_implementations(typ)
        self.check_interface_errors(typ)
        self.check_no_constructor_if_interface(typ)
        self.accept(defn.defs)
        self.errors.set_type(None, False)

    def check_no_constructor_if_interface(self, typ):
        if not typ.is_interface:
开发者ID:SRiikonen,项目名称:mypy-py,代码行数:70,代码来源:checker.py


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