本文整理汇总了Python中mypy.nodes.FuncDef.init方法的典型用法代码示例。如果您正苦于以下问题:Python FuncDef.init方法的具体用法?Python FuncDef.init怎么用?Python FuncDef.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.FuncDef
的用法示例。
在下文中一共展示了FuncDef.init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepend_generic_function_tvar_args
# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import init [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