当前位置: 首页>>代码示例>>Python>>正文


Python FuncDef.is_constructor方法代码示例

本文整理汇总了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
开发者ID:FlorianLudwig,项目名称:mypy,代码行数:44,代码来源:transformfunc.py


注:本文中的mypy.nodes.FuncDef.is_constructor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。