本文整理汇总了Python中mypy.messages.MessageBuilder.incompatible_self_argument方法的典型用法代码示例。如果您正苦于以下问题:Python MessageBuilder.incompatible_self_argument方法的具体用法?Python MessageBuilder.incompatible_self_argument怎么用?Python MessageBuilder.incompatible_self_argument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.messages.MessageBuilder
的用法示例。
在下文中一共展示了MessageBuilder.incompatible_self_argument方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_self_arg
# 需要导入模块: from mypy.messages import MessageBuilder [as 别名]
# 或者: from mypy.messages.MessageBuilder import incompatible_self_argument [as 别名]
def check_self_arg(functype: FunctionLike,
dispatched_arg_type: Type,
is_classmethod: bool,
context: Context, name: str,
msg: MessageBuilder) -> None:
"""For x.f where A.f: A1 -> T, check that meet(type(x), A) <: A1 for each overload.
dispatched_arg_type is meet(B, A) in the following example
def g(x: B): x.f
class A:
f: Callable[[A1], None]
"""
# TODO: this is too strict. We can return filtered overloads for matching definitions
for item in functype.items():
if not item.arg_types or item.arg_kinds[0] not in (ARG_POS, ARG_STAR):
# No positional first (self) argument (*args is okay).
msg.no_formal_self(name, item, context)
else:
selfarg = item.arg_types[0]
if is_classmethod:
dispatched_arg_type = TypeType.make_normalized(dispatched_arg_type)
if not subtypes.is_subtype(dispatched_arg_type, erase_to_bound(selfarg)):
msg.incompatible_self_argument(name, dispatched_arg_type, item,
is_classmethod, context)