• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python types.Overloaded类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: no_variant_matches_arguments

 def no_variant_matches_arguments(self, overload: Overloaded,
                                   context: Context) -> None:
     if overload.name():
         self.fail('No overload variant of {} matches argument types'
                   .format(overload.name()), context)
     else:
         self.fail('No overload variant matches argument types', context)
开发者ID:silky,项目名称:mypy,代码行数:7,代码来源:messages.py


示例2: no_variant_matches_arguments

 def no_variant_matches_arguments(self, overload: Overloaded, arg_types: List[Type],
                                  context: Context) -> None:
     if overload.name():
         self.fail('No overload variant of {} matches argument types {}'
                   .format(overload.name(), arg_types), context)
     else:
         self.fail('No overload variant matches argument types {}'.format(arg_types), context)
开发者ID:o11c,项目名称:mypy,代码行数:7,代码来源:messages.py


示例3: visit_overloaded

 def visit_overloaded(self, t: Overloaded) -> Type:
     items = []  # type: List[CallableType]
     for item in t.items():
         new_item = item.accept(self)
         assert isinstance(new_item, CallableType)
         items.append(new_item)
     return Overloaded(items)
开发者ID:Michael0x2a,项目名称:mypy,代码行数:7,代码来源:expandtype.py


示例4: visit_overloaded

 def visit_overloaded(self, t: Overloaded) -> Type:
     # TODO: Implement a better algorithm that covers at least the same cases
     # as TypeJoinVisitor.visit_overloaded().
     s = self.s
     if isinstance(s, FunctionLike):
         if s.items() == t.items():
             return Overloaded(t.items())
         elif is_subtype(s, t):
             return s
         elif is_subtype(t, s):
             return t
         else:
             return meet_types(t.fallback, s.fallback)
     elif isinstance(self.s, Instance) and self.s.type.is_protocol:
         call = unpack_callback_protocol(self.s)
         if call:
             return meet_types(t, call)
     return meet_types(t.fallback, s)
开发者ID:chadrik,项目名称:mypy,代码行数:18,代码来源:meet.py


示例5: visit_overloaded

 def visit_overloaded(self, t: Overloaded) -> Type:
     items = []  # type: List[CallableType]
     for item in t.items():
         new = item.accept(self)
         if isinstance(new, CallableType):
             items.append(new)
         else:
             raise RuntimeError('CallableType expected, but got {}'.format(type(new)))
     return Overloaded(items=items)
开发者ID:Michael0x2a,项目名称:mypy,代码行数:9,代码来源:type_visitor.py


示例6: infer_against_overloaded

 def infer_against_overloaded(self, overloaded: Overloaded,
                              template: Callable) -> List[Constraint]:
     # Create constraints by matching an overloaded type against a template.
     # This is tricky to do in general. We cheat by only matching against
     # the first overload item, and by only matching the return type. This
     # seems to work somewhat well, but we should really use a more
     # reliable technique.
     item = overloaded.items()[0]
     return infer_constraints(template.ret_type, item.ret_type,
                              self.direction)
开发者ID:thisfred,项目名称:mypy,代码行数:10,代码来源:constraints.py


示例7: find_matching_overload_item

def find_matching_overload_item(overloaded: Overloaded, template: CallableType) -> CallableType:
    """Disambiguate overload item against a template."""
    items = overloaded.items()
    for item in items:
        # Return type may be indeterminate in the template, so ignore it when performing a
        # subtype check.
        if mypy.subtypes.is_callable_subtype(item, template, ignore_return=True):
            return item
    # Fall back to the first item if we can't find a match. This is totally arbitrary --
    # maybe we should just bail out at this point.
    return items[0]
开发者ID:alexandrul,项目名称:mypy,代码行数:11,代码来源:constraints.py


示例8: visit_overloaded

 def visit_overloaded(self, left: Overloaded) -> bool:
     right = self.right
     if isinstance(right, Instance):
         return is_subtype(left.fallback, right)
     elif isinstance(right, CallableType) or is_named_instance(right, "builtins.type"):
         for item in left.items():
             if is_subtype(item, right, self.check_type_parameter):
                 return True
         return False
     elif isinstance(right, Overloaded):
         # TODO: this may be too restrictive
         if len(left.items()) != len(right.items()):
             return False
         for i in range(len(left.items())):
             if not is_subtype(left.items()[i], right.items()[i], self.check_type_parameter):
                 return False
         return True
     elif isinstance(right, UnboundType):
         return True
     else:
         return False
开发者ID:nierob,项目名称:mypy,代码行数:21,代码来源:subtypes.py


示例9: visit_overloaded

 def visit_overloaded(self, left: Overloaded) -> bool:
     right = self.right
     if isinstance(right, Instance):
         return is_subtype(left.fallback, right)
     elif isinstance(right, CallableType) or is_named_instance(
             right, 'builtins.type'):
         for item in left.items():
             if is_subtype(item, right, self.check_type_parameter,
                           ignore_pos_arg_names=self.ignore_pos_arg_names):
                 return True
         return False
     elif isinstance(right, Overloaded):
         # TODO: this may be too restrictive
         if len(left.items()) != len(right.items()):
             return False
         for i in range(len(left.items())):
             if not is_subtype(left.items()[i], right.items()[i], self.check_type_parameter,
                               ignore_pos_arg_names=self.ignore_pos_arg_names):
                 return False
         return True
     elif isinstance(right, UnboundType):
         return True
     elif isinstance(right, TypeType):
         # All the items must have the same type object status, so
         # it's sufficient to query only (any) one of them.
         # This is unsound, we don't check the __init__ signature.
         return left.is_type_obj() and is_subtype(left.items()[0].ret_type, right.item)
     else:
         return False
开发者ID:alexandrul,项目名称:mypy,代码行数:29,代码来源:subtypes.py


示例10: visit_overloaded

 def visit_overloaded(self, t: Overloaded) -> Type:
     # This is more complex than most other cases. Here are some
     # examples that illustrate how this works.
     #
     # First let's define a concise notation:
     #  - Cn are callable types (for n in 1, 2, ...)
     #  - Ov(C1, C2, ...) is an overloaded type with items C1, C2, ...
     #  - Callable[[T, ...], S] is written as [T, ...] -> S.
     #
     # We want some basic properties to hold (assume Cn are all
     # unrelated via Any-similarity):
     #
     #   join(Ov(C1, C2), C1) == C1
     #   join(Ov(C1, C2), Ov(C1, C2)) == Ov(C1, C2)
     #   join(Ov(C1, C2), Ov(C1, C3)) == C1
     #   join(Ov(C2, C2), C3) == join of fallback types
     #
     # The presence of Any types makes things more interesting. The join is the
     # most general type we can get with respect to Any:
     #
     #   join(Ov([int] -> int, [str] -> str), [Any] -> str) == Any -> str
     #
     # We could use a simplification step that removes redundancies, but that's not
     # implemented right now. Consider this example, where we get a redundancy:
     #
     #   join(Ov([int, Any] -> Any, [str, Any] -> Any), [Any, int] -> Any) ==
     #       Ov([Any, int] -> Any, [Any, int] -> Any)
     #
     # TODO: Consider more cases of callable subtyping.
     result = []  # type: List[CallableType]
     s = self.s
     if isinstance(s, FunctionLike):
         # The interesting case where both types are function types.
         for t_item in t.items():
             for s_item in s.items():
                 if is_similar_callables(t_item, s_item):
                     if is_equivalent(t_item, s_item):
                         result.append(combine_similar_callables(t_item, s_item))
                     elif is_subtype(t_item, s_item):
                         result.append(s_item)
         if result:
             # TODO: Simplify redundancies from the result.
             if len(result) == 1:
                 return result[0]
             else:
                 return Overloaded(result)
         return join_types(t.fallback, s.fallback)
     elif isinstance(s, Instance) and s.type.is_protocol:
         call = unpack_callback_protocol(s)
         if call:
             return join_types(t, call)
     return join_types(t.fallback, s)
开发者ID:chadrik,项目名称:mypy,代码行数:52,代码来源:join.py


示例11: visit_overloaded

 def visit_overloaded(self, left: Overloaded) -> bool:
     right = self.right
     if is_named_instance(right, 'builtins.object'):
         return True
     elif isinstance(right, Callable) or is_named_instance(
                                              right, 'builtins.type'):
         for item in left.items():
             if is_subtype(item, right):
                 return True
         return False
     elif isinstance(right, Overloaded):
         # TODO: this may be too restrictive
         if len(left.items()) != len(right.items()):
             return False
         for i in range(len(left.items())):
             if not is_subtype(left.items()[i], right.items()[i]):
                 return False
         return True
     elif isinstance(right, UnboundType):
         return True
     else:
         return False
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:22,代码来源:subtypes.py


示例12: visit_overloaded

 def visit_overloaded(self, t: Overloaded) -> Type:
     items = [] # type: List[Callable]
     for item in t.items():
         items.append(cast(Callable, item.accept(self)))
     return Overloaded(items)
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:5,代码来源:expandtype.py


示例13: visit_overloaded

    def visit_overloaded(self, left: Overloaded) -> bool:
        right = self.right
        if isinstance(right, Instance):
            return is_subtype(left.fallback, right)
        elif isinstance(right, CallableType):
            for item in left.items():
                if is_subtype(item, right, self.check_type_parameter,
                              ignore_pos_arg_names=self.ignore_pos_arg_names):
                    return True
            return False
        elif isinstance(right, Overloaded):
            # Ensure each overload in the right side (the supertype) is accounted for.
            previous_match_left_index = -1
            matched_overloads = set()
            possible_invalid_overloads = set()

            for right_index, right_item in enumerate(right.items()):
                found_match = False

                for left_index, left_item in enumerate(left.items()):
                    subtype_match = is_subtype(left_item, right_item, self.check_type_parameter,
                                               ignore_pos_arg_names=self.ignore_pos_arg_names)

                    # Order matters: we need to make sure that the index of
                    # this item is at least the index of the previous one.
                    if subtype_match and previous_match_left_index <= left_index:
                        if not found_match:
                            # Update the index of the previous match.
                            previous_match_left_index = left_index
                            found_match = True
                            matched_overloads.add(left_item)
                            possible_invalid_overloads.discard(left_item)
                    else:
                        # If this one overlaps with the supertype in any way, but it wasn't
                        # an exact match, then it's a potential error.
                        if (is_callable_subtype(left_item, right_item, ignore_return=True,
                                            ignore_pos_arg_names=self.ignore_pos_arg_names) or
                                is_callable_subtype(right_item, left_item, ignore_return=True,
                                                ignore_pos_arg_names=self.ignore_pos_arg_names)):
                            # If this is an overload that's already been matched, there's no
                            # problem.
                            if left_item not in matched_overloads:
                                possible_invalid_overloads.add(left_item)

                if not found_match:
                    return False

            if possible_invalid_overloads:
                # There were potentially invalid overloads that were never matched to the
                # supertype.
                return False
            return True
        elif isinstance(right, UnboundType):
            return True
        elif isinstance(right, TypeType):
            # All the items must have the same type object status, so
            # it's sufficient to query only (any) one of them.
            # This is unsound, we don't check all the __init__ signatures.
            return left.is_type_obj() and is_subtype(left.items()[0], right)
        else:
            return False
开发者ID:sixolet,项目名称:mypy,代码行数:61,代码来源:subtypes.py


示例14: visit_overloaded

 def visit_overloaded(self, t: Overloaded) -> Type:
     return t.items()[0].accept(self)
开发者ID:JamesGuthrie,项目名称:mypy,代码行数:2,代码来源:erasetype.py


示例15: visit_overloaded

 def visit_overloaded(self, t: Overloaded) -> None:
     for item in t.items():
         item.accept(self)
开发者ID:greatmazinger,项目名称:mypy,代码行数:3,代码来源:typeanal.py


示例16: visit_overloaded

 def visit_overloaded(self, template: Overloaded) -> List[Constraint]:
     res = []  # type: List[Constraint]
     for t in template.items():
         res.extend(infer_constraints(t, self.actual, self.direction))
     return res
开发者ID:alexandrul,项目名称:mypy,代码行数:5,代码来源:constraints.py


示例17: visit_overloaded

 def visit_overloaded(self, typ: Overloaded) -> SnapshotItem:
     return ('Overloaded', snapshot_types(typ.items()))
开发者ID:greatmazinger,项目名称:mypy,代码行数:2,代码来源:astdiff.py


示例18: visit_overloaded

 def visit_overloaded(self, t: Overloaded) -> None:
     for item in t.items():
         item.accept(self)
     # Fallback can be None for overloaded types that haven't been semantically analyzed.
     if t.fallback is not None:
         t.fallback.accept(self)
开发者ID:python,项目名称:mypy,代码行数:6,代码来源:astmerge.py


示例19: visit_overloaded

 def visit_overloaded(self, t: Overloaded) -> None:
     self.traverse_types(t.items())
开发者ID:python,项目名称:mypy,代码行数:2,代码来源:typetraverser.py


示例20: visit_overloaded

 def visit_overloaded(self, t: types.Overloaded) -> Set[str]:
     return self._visit(t.items()) | self._visit(t.fallback)
开发者ID:chadrik,项目名称:mypy,代码行数:2,代码来源:indirection.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python types.TupleType类代码示例发布时间:2022-05-27
下一篇:
Python types.Instance类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap