本文整理汇总了Python中mypy.nodes.FuncDef.is_constructor方法的典型用法代码示例。如果您正苦于以下问题:Python FuncDef.is_constructor方法的具体用法?Python FuncDef.is_constructor怎么用?Python FuncDef.is_constructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.nodes.FuncDef
的用法示例。
在下文中一共展示了FuncDef.is_constructor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transform_method
# 需要导入模块: from mypy.nodes import FuncDef [as 别名]
# 或者: from mypy.nodes.FuncDef import is_constructor [as 别名]
def transform_method(self, fdef: FuncDef) -> List[FuncDef]:
"""Transform a method.
The result is one or more methods.
"""
# Transform the body of the method.
self.tf.transform_function_body(fdef)
res = Undefined # type: List[FuncDef]
if fdef.is_constructor():
# The method is a constructor. Constructors are transformed to one
# method.
res = [self.transform_method_implementation(fdef, fdef.name())]
else:
# Normal methods are transformed to 1-3 variants. The
# first is the main implementation of the method, and the
# second is the dynamically-typed wrapper. The third
# variant is for method overrides, and represents the
# overridden supertype method.
res = [self.transform_method_implementation(
fdef, fdef.name() + self.tf.type_suffix(fdef))]
if fdef.info.bases and fdef.info.mro[1].has_method(fdef.name()):
# Override.
# TODO do not assume single inheritance
# Is is an override with a different signature? For
# trivial overrides we can inherit wrappers.
if not is_simple_override(fdef, fdef.info):
# Create a wrapper for overridden superclass method.
res.append(self.override_method_wrapper(fdef))
# Create a dynamically-typed method wrapper.
res.append(self.dynamic_method_wrapper(fdef))
else:
# Not an override.
# Create a dynamically-typed method wrapper.
res.append(self.dynamic_method_wrapper(fdef))
return res