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


Python op_methods.items函数代码示例

本文整理汇总了Python中mypy.nodes.op_methods.items函数的典型用法代码示例。如果您正苦于以下问题:Python items函数的具体用法?Python items怎么用?Python items使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: has_no_attr

    def has_no_attr(self, typ: Type, member: str, context: Context) -> Type:
        """Report a missing or non-accessible member.

        The type argument is the base type. If member corresponds to
        an operator, use the corresponding operator name in the
        messages. Return type Any.
        """
        if (isinstance(typ, Instance) and
                (cast(Instance, typ)).type.has_readable_member(member)):
            self.fail('Member "{}" is not assignable'.format(member), context)
        elif isinstance(typ, Void):
            self.check_void(typ, context)
        elif member == '__contains__':
            self.fail('Unsupported right operand type for in ({})'.format(
                self.format(typ)), context)
        elif member in op_methods.values():
            # Access to a binary operator member (e.g. _add). This case does
            # not handle indexing operations.
            for op, method in op_methods.items():
                if method == member:
                    self.unsupported_left_operand(op, typ, context)
                    break
        elif member == '__neg__':
            self.fail('Unsupported operand type for unary - ({})'.format(
                self.format(typ)), context)
        elif member == '__pos__':
            self.fail('Unsupported operand type for unary + ({})'.format(
                self.format(typ)), context)
        elif member == '__invert__':
            self.fail('Unsupported operand type for ~ ({})'.format(
                self.format(typ)), context)
        elif member == '__getitem__':
            # Indexed get.
            self.fail('Value of type {} is not indexable'.format(
                self.format(typ)), context)
        elif member == '__setitem__':
            # Indexed set.
            self.fail('Unsupported target for indexed assignment', context)
        elif member == '__call__':
            self.fail('{} not callable'.format(self.format(typ)), context)
        else:
            # The non-special case: a missing ordinary attribute.
            if not self.disable_type_names:
                failed = False
                if isinstance(typ, Instance) and cast(Instance, typ).type.names:
                    typ = cast(Instance, typ)
                    alternatives = set(typ.type.names.keys())
                    matches = [m for m in COMMON_MISTAKES.get(member, []) if m in alternatives]
                    matches.extend(best_matches(member, alternatives)[:3])
                    if matches:
                        self.fail('{} has no attribute "{}"; maybe {}?'.format(
                            self.format(typ), member, pretty_or(matches)), context)
                        failed = True
                if not failed:
                    self.fail('{} has no attribute "{}"'.format(self.format(typ),
                                                                member), context)
            else:
                self.fail('Some element of union has no attribute "{}"'.format(
                    member), context)
        return AnyType()
开发者ID:o11c,项目名称:mypy,代码行数:60,代码来源:messages.py

示例2: incompatible_argument

    def incompatible_argument(self, n: int, callee: Callable, arg_type: Type,
                              context: Context) -> None:
        """Report an error about an incompatible argument type.

        The argument type is arg_type, argument number is n and the
        callee type is 'callee'. If the callee represents a method
        that corresponds to an operator, use the corresponding
        operator name in the messages.
        """
        target = ''
        if callee.name:
            name = callee.name
            base = extract_type(name)
            
            for op, method in op_methods.items():
                for variant in method, '__r' + method[2:]:
                    if name.startswith('"{}" of'.format(variant)):
                        if op == 'in' or variant != method:
                            # Reversed order of base/argument.
                            self.unsupported_operand_types(op, arg_type, base,
                                                           context)
                        else:
                            self.unsupported_operand_types(op, base, arg_type,
                                                           context)
                        return 
            
            if name.startswith('"__getitem__" of'):
                self.invalid_index_type(arg_type, base, context)
                return 
            
            if name.startswith('"__setitem__" of'):
                if n == 1:
                    self.invalid_index_type(arg_type, base, context)
                else:
                    self.fail(INCOMPATIBLE_TYPES_IN_ASSIGNMENT, context)
                return 
            
            target = 'to {} '.format(name)
        
        msg = ''
        if callee.name == '<list>':
            name = callee.name[1:-1]
            msg = '{} item {} has incompatible type {}'.format(
                name[0].upper() + name[1:], n, self.format_simple(arg_type))
        elif callee.name == '<list-comprehension>':
            msg = 'List comprehension has incompatible type List[{}]'.format(
                                  strip_quotes(self.format(arg_type)))
        elif callee.name == '<generator>':
            msg = 'Generator has incompatible item type {}'.format(
                                              self.format_simple(arg_type))
        else:
            try:
                expected_type = callee.arg_types[n-1]
            except IndexError:  # Varargs callees
                expected_type = callee.arg_types[-1]
            msg = 'Argument {} {}has incompatible type {}; expected {}'.format(
                n, target, self.format(arg_type), self.format(expected_type))
        self.fail(msg, context)
开发者ID:mvcisback,项目名称:mypy,代码行数:58,代码来源:messages.py

示例3: incompatible_argument

 def incompatible_argument(self, n, callee, arg_type, context):
     """Report an error about an incompatible type arg_type for
     argument n when calling a value with type callee. If the
     callee represents a method that corresponds to an operator,
     use the corresponding operator name in the messages.
     """
     target = ''
     if callee.name:
         name = callee.name
         base = extract_type(name)
         
         for op, method in op_methods.items():
             if name.startswith('"{}" of'.format(method)):
                 if op == 'in':
                     self.unsupported_operand_types(op, arg_type, base,
                                                    context)
                 else:
                     self.unsupported_operand_types(op, base, arg_type,
                                                    context)
                 return 
         
         if name.startswith('"__getitem__" of'):
             self.invalid_index_type(arg_type, base, context)
             return 
         
         if name.startswith('"__setitem__" of'):
             if n == 1:
                 self.invalid_index_type(arg_type, base, context)
             else:
                 self.fail(INCOMPATIBLE_TYPES_IN_ASSIGNMENT, context)
             return 
         
         if name.startswith('method "create" of '):
             name = base
         target = 'to {} '.format(name)
     
     msg = None
     if callee.name == '<list>':
         name = callee.name[1:-1]
         msg = '{} item {} has incompatible type {}'.format(
             name[0].upper() + name[1:], n, self.format_simple(arg_type))
     elif callee.name == '<list-comprehension>':
         msg = 'List comprehension has incompatible type {}[]'.format(
                               strip_quotes(self.format_simple(arg_type)))
     elif callee.name == '<generator>':
         msg = 'Generator has incompatible item type {}'.format(
                                           self.format_simple(arg_type))
     else:
         msg = 'Argument {} {}has incompatible type {}'.format(
             n, target, self.format_simple(arg_type))
     self.fail(msg, context)
开发者ID:SRiikonen,项目名称:mypy-py,代码行数:51,代码来源:messages.py

示例4: has_no_attr

    def has_no_attr(self, typ: Type, member: str, context: Context) -> Type:
        """Report a missing or non-accessible member.

        The type argument is the base type. If member corresponds to
        an operator, use the corresponding operator name in the
        messages. Return type Any.
        """
        if (isinstance(typ, Instance) and
                (cast(Instance, typ)).type.has_readable_member(member)):
            self.fail('Member "{}" is not assignable'.format(member), context)
        elif isinstance(typ, Void):
            self.check_void(typ, context)
        elif member == '__contains__':
            self.fail('Unsupported right operand type for in ({})'.format(
                self.format(typ)), context)
        elif member in op_methods.values():
            # Access to a binary operator member (e.g. _add). This case does
            # not handle indexing operations.
            for op, method in op_methods.items():
                if method == member:
                    self.unsupported_left_operand(op, typ, context)
                    break
        elif member == '__neg__':
            self.fail('Unsupported operand type for unary - ({})'.format(
                self.format(typ)), context)
        elif member == '__invert__':
            self.fail('Unsupported operand type for ~ ({})'.format(
                self.format(typ)), context)
        elif member == '__getitem__':
            # Indexed get.
            self.fail('Value of type {} is not indexable'.format(
                self.format(typ)), context)
        elif member == '__setitem__':
            # Indexed set.
            self.fail('Unsupported target for indexed assignment', context)
        else:
            # The non-special case: a missing ordinary attribute.
            self.fail('{} has no attribute "{}"'.format(self.format(typ),
                                                        member), context)
        return AnyType()
开发者ID:silky,项目名称:mypy,代码行数:40,代码来源:messages.py

示例5: isinstance

 argument is the base type. If member corresponds to an
 operator, use the corresponding operator name in the
 messages. Return type Any.
 """
 if (isinstance(typ, Instance) and
         ((Instance)typ).type.has_readable_member(member)):
     self.fail('Member "{}" is not assignable'.format(member), context)
 elif isinstance(typ, Void):
     self.check_void(typ, context)
 elif member == '__contains__':
     self.fail('Unsupported right operand type for in ({})'.format(
         self.format(typ)), context)
 elif member in op_methods.values():
     # Access to a binary operator member (e.g. _add). This case does
     # not handle indexing operations.
     for op, method in op_methods.items():
         if method == member:
             self.unsupported_left_operand(op, typ, context)
             break
 elif member == '__neg__':
     self.fail('Unsupported operand type for unary - ({})'.format(
         self.format(typ)), context)
 elif member == '__invert__':
     self.fail('Unsupported operand type for ~ ({})'.format(
         self.format(typ)), context)
 elif member == '__getitem__':
     # Indexed get.
     self.fail('Value of type {} is not indexable'.format(
         self.format(typ)), context)
 elif member == '__setitem__':
     # Indexed set.
开发者ID:SRiikonen,项目名称:mypy,代码行数:31,代码来源:messages.py

示例6: incompatible_argument

    def incompatible_argument(
        self, n: int, m: int, callee: CallableType, arg_type: Type, arg_kind: int, context: Context
    ) -> None:
        """Report an error about an incompatible argument type.

        The argument type is arg_type, argument number is n and the
        callee type is 'callee'. If the callee represents a method
        that corresponds to an operator, use the corresponding
        operator name in the messages.
        """
        target = ""
        if callee.name:
            name = callee.name
            base = extract_type(name)

            for op, method in op_methods.items():
                for variant in method, "__r" + method[2:]:
                    if name.startswith('"{}" of'.format(variant)):
                        if op == "in" or variant != method:
                            # Reversed order of base/argument.
                            self.unsupported_operand_types(op, arg_type, base, context)
                        else:
                            self.unsupported_operand_types(op, base, arg_type, context)
                        return

            if name.startswith('"__getitem__" of'):
                self.invalid_index_type(arg_type, base, context)
                return

            if name.startswith('"__setitem__" of'):
                if n == 1:
                    self.invalid_index_type(arg_type, base, context)
                else:
                    self.fail(INCOMPATIBLE_TYPES_IN_ASSIGNMENT, context)
                return

            target = "to {} ".format(name)

        msg = ""
        if callee.name == "<list>":
            name = callee.name[1:-1]
            n -= 1
            msg = "{} item {} has incompatible type {}".format(
                name[0].upper() + name[1:], n, self.format_simple(arg_type)
            )
        elif callee.name == "<list-comprehension>":
            msg = "List comprehension has incompatible type List[{}]".format(strip_quotes(self.format(arg_type)))
        elif callee.name == "<set-comprehension>":
            msg = "Set comprehension has incompatible type Set[{}]".format(strip_quotes(self.format(arg_type)))
        elif callee.name == "<dictionary-comprehension>":
            msg = ("{} expression in dictionary comprehension has incompatible type {}; " "expected type {}").format(
                "Key" if n == 1 else "Value", self.format(arg_type), self.format(callee.arg_types[n - 1])
            )
        elif callee.name == "<generator>":
            msg = "Generator has incompatible item type {}".format(self.format_simple(arg_type))
        else:
            try:
                expected_type = callee.arg_types[m - 1]
            except IndexError:  # Varargs callees
                expected_type = callee.arg_types[-1]
            arg_type_str, expected_type_str = self.format_distinctly(arg_type, expected_type)
            if arg_kind == ARG_STAR:
                arg_type_str = "*" + arg_type_str
            elif arg_kind == ARG_STAR2:
                arg_type_str = "**" + arg_type_str
            msg = "Argument {} {}has incompatible type {}; expected {}".format(
                n, target, arg_type_str, expected_type_str
            )
        self.fail(msg, context)
开发者ID:judasnow,项目名称:mypy,代码行数:69,代码来源:messages.py


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