本文整理汇总了Python中mypy.types.CallableType.accept方法的典型用法代码示例。如果您正苦于以下问题:Python CallableType.accept方法的具体用法?Python CallableType.accept怎么用?Python CallableType.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.types.CallableType
的用法示例。
在下文中一共展示了CallableType.accept方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: analyze_callable_type
# 需要导入模块: from mypy.types import CallableType [as 别名]
# 或者: from mypy.types.CallableType import accept [as 别名]
def analyze_callable_type(self, t: UnboundType) -> Type:
fallback = self.named_type('builtins.function')
if len(t.args) == 0:
# Callable (bare). Treat as Callable[..., Any].
any_type = AnyType(TypeOfAny.from_omitted_generics,
line=t.line, column=t.column)
ret = CallableType([any_type, any_type],
[nodes.ARG_STAR, nodes.ARG_STAR2],
[None, None],
ret_type=any_type,
fallback=fallback,
is_ellipsis_args=True)
elif len(t.args) == 2:
ret_type = t.args[1]
if isinstance(t.args[0], TypeList):
# Callable[[ARG, ...], RET] (ordinary callable type)
analyzed_args = self.analyze_callable_args(t.args[0])
if analyzed_args is None:
return AnyType(TypeOfAny.from_error)
args, kinds, names = analyzed_args
ret = CallableType(args,
kinds,
names,
ret_type=ret_type,
fallback=fallback)
elif isinstance(t.args[0], EllipsisType):
# Callable[..., RET] (with literal ellipsis; accept arbitrary arguments)
ret = CallableType([AnyType(TypeOfAny.explicit),
AnyType(TypeOfAny.explicit)],
[nodes.ARG_STAR, nodes.ARG_STAR2],
[None, None],
ret_type=ret_type,
fallback=fallback,
is_ellipsis_args=True)
else:
self.fail('The first argument to Callable must be a list of types or "..."', t)
return AnyType(TypeOfAny.from_error)
else:
self.fail('Please use "Callable[[<parameters>], <return type>]" or "Callable"', t)
return AnyType(TypeOfAny.from_error)
assert isinstance(ret, CallableType)
return ret.accept(self)
示例2: convert_class_tvars_to_func_tvars
# 需要导入模块: from mypy.types import CallableType [as 别名]
# 或者: from mypy.types.CallableType import accept [as 别名]
def convert_class_tvars_to_func_tvars(callable: CallableType,
num_func_tvars: int) -> CallableType:
return cast(CallableType, callable.accept(TvarTranslator(num_func_tvars)))