本文整理汇总了Python中mypy.types.CallableType.argument_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python CallableType.argument_by_name方法的具体用法?Python CallableType.argument_by_name怎么用?Python CallableType.argument_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.types.CallableType
的用法示例。
在下文中一共展示了CallableType.argument_by_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_callable_subtype
# 需要导入模块: from mypy.types import CallableType [as 别名]
# 或者: from mypy.types.CallableType import argument_by_name [as 别名]
#.........这里部分代码省略.........
right.arg_names[i],
right_pos,
right.arg_types[i],
right_required)
if right_kind == ARG_STAR:
right_star_type = right_arg.typ
# Right has an infinite series of optional positional arguments
# here. Get all further positional arguments of left, and make sure
# they're more general than their corresponding member in this
# series. Also make sure left has its own inifite series of
# optional positional arguments.
if not left.is_var_arg:
return False
j = i
while j < len(left.arg_kinds) and left.arg_kinds[j] in (ARG_POS, ARG_OPT):
left_by_position = left.argument_by_position(j)
assert left_by_position is not None
# This fetches the synthetic argument that's from the *args
right_by_position = right.argument_by_position(j)
assert right_by_position is not None
if not are_args_compatible(left_by_position, right_by_position,
ignore_pos_arg_names):
return False
j += 1
continue
if right_kind == ARG_STAR2:
right_star2_type = right_arg.typ
# Right has an infinite set of optional named arguments here. Get
# all further named arguments of left and make sure they're more
# general than their corresponding member in this set. Also make
# sure left has its own infinite set of optional named arguments.
if not left.is_kw_arg:
return False
left_names = {name for name in left.arg_names if name is not None}
right_names = {name for name in right.arg_names if name is not None}
left_only_names = left_names - right_names
for name in left_only_names:
left_by_name = left.argument_by_name(name)
assert left_by_name is not None
# This fetches the synthetic argument that's from the **kwargs
right_by_name = right.argument_by_name(name)
assert right_by_name is not None
if not are_args_compatible(left_by_name, right_by_name,
ignore_pos_arg_names):
return False
continue
# Left must have some kind of corresponding argument.
left_arg = left.corresponding_argument(right_arg)
if left_arg is None:
return False
if not are_args_compatible(left_arg, right_arg, ignore_pos_arg_names):
return False
done_with_positional = False
for i in range(len(left.arg_types)):
left_kind = left.arg_kinds[i]
if left_kind in (ARG_STAR, ARG_STAR2, ARG_NAMED, ARG_NAMED_OPT):
done_with_positional = True
left_arg = FormalArgument(
left.arg_names[i],
None if done_with_positional else i,
left.arg_types[i],
left_kind in (ARG_POS, ARG_NAMED))
# Check that *args and **kwargs types match in this loop
if left_kind == ARG_STAR:
if right_star_type is not None and not is_subtype(right_star_type, left_arg.typ):
return False
continue
elif left_kind == ARG_STAR2:
if right_star2_type is not None and not is_subtype(right_star2_type, left_arg.typ):
return False
continue
right_by_name = (right.argument_by_name(left_arg.name)
if left_arg.name is not None
else None)
right_by_pos = (right.argument_by_position(left_arg.pos)
if left_arg.pos is not None
else None)
# If the left hand argument corresponds to two right-hand arguments,
# neither of them can be required.
if (right_by_name is not None
and right_by_pos is not None
and right_by_name != right_by_pos
and (right_by_pos.required or right_by_name.required)):
return False
# All *required* left-hand arguments must have a corresponding
# right-hand argument. Optional args it does not matter.
if left_arg.required and right_by_pos is None and right_by_name is None:
return False
return True