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


Python MessageBuilder.argument_incompatible_with_supertype方法代码示例

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


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

示例1: TypeChecker

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

#.........这里部分代码省略.........
            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:
            return
        ctor = typ.get_method('__init__')
        if ctor is None:
            return
        self.msg.interface_has_constructor(ctor)
    
    def check_unique_interface_implementations(self, typ):
        """Check that each interface is implemented only once."""
        ifaces = typ.interfaces[:]
        
        dup = find_duplicate(ifaces)
        if dup:
            self.msg.duplicate_interfaces(typ, dup)
            return 
开发者ID:SRiikonen,项目名称:mypy-py,代码行数:70,代码来源:checker.py


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