本文整理汇总了Python中mypy.nodes.FuncDef.is_method方法的典型用法代码示例。如果您正苦于以下问题:Python FuncDef.is_method方法的具体用法?Python FuncDef.is_method怎么用?Python FuncDef.is_method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.FuncDef
的用法示例。
在下文中一共展示了FuncDef.is_method方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call_wrapper
# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import is_method [as 别名]
def call_wrapper(self, fdef: FuncDef, is_dynamic: bool,
is_wrapper_class: bool, target_ann: Callable,
cur_ann: Callable, target_suffix: str,
bound_sig: Callable) -> Node:
"""Return the body of wrapper method.
The body contains only a call to the wrapped method and a
return statement (if the call returns a value). Arguments are coerced
to the target signature.
"""
args = self.call_args(fdef.args, target_ann, cur_ann, is_dynamic,
is_wrapper_class, bound_sig,
ismethod=fdef.is_method())
selfarg = args[0]
args = args[1:]
member = fdef.name() + target_suffix
if not is_wrapper_class:
callee = MemberExpr(selfarg, member)
else:
callee = MemberExpr(
MemberExpr(self_expr(), self.tf.object_member_name()), member)
call = CallExpr(callee,
args,
[nodes.ARG_POS] * len(args),
[None] * len(args)) # type: Node
if bound_sig:
call = self.tf.coerce(call, bound_sig.ret_type,
target_ann.ret_type, self.tf.type_context(),
is_wrapper_class)
call = self.tf.coerce(call, cur_ann.ret_type, bound_sig.ret_type,
self.tf.type_context(), is_wrapper_class)
else:
call = self.tf.coerce(call, cur_ann.ret_type, target_ann.ret_type,
self.tf.type_context(), is_wrapper_class)
if not isinstance(target_ann.ret_type, Void):
return ReturnStmt(call)
else:
return ExpressionStmt(call)
示例2: prepend_generic_function_tvar_args
# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import is_method [as 别名]
def prepend_generic_function_tvar_args(self, fdef: FuncDef) -> None:
"""Add implicit function type variable arguments if fdef is generic."""
sig = cast(Callable, function_type(fdef))
tvars = sig.variables
if not fdef.type:
fdef.type = sig
tv = [] # type: List[Var]
ntvars = len(tvars)
if fdef.is_method():
# For methods, add type variable arguments after the self arg.
for n in range(ntvars):
tv.append(Var(tvar_arg_name(-1 - n)))
fdef.type = add_arg_type_after_self(cast(Callable, fdef.type), AnyType())
fdef.args = [fdef.args[0]] + tv + fdef.args[1:]
else:
# For ordinary functions, prepend type variable arguments.
for n in range(ntvars):
tv.append(Var(tvar_arg_name(-1 - n)))
fdef.type = prepend_arg_type(cast(Callable, fdef.type), AnyType())
fdef.args = tv + fdef.args
fdef.init = List[AssignmentStmt]([None]) * ntvars + fdef.init