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


Python _ast.ClassDef方法代码示例

本文整理汇总了Python中_ast.ClassDef方法的典型用法代码示例。如果您正苦于以下问题:Python _ast.ClassDef方法的具体用法?Python _ast.ClassDef怎么用?Python _ast.ClassDef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_ast的用法示例。


在下文中一共展示了_ast.ClassDef方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CONTINUE

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import ClassDef [as 别名]
def CONTINUE(self, node):
        # Walk the tree up until we see a loop (OK), a function or class
        # definition (not OK), for 'continue', a finally block (not OK), or
        # the top module scope (not OK)
        n = node
        while hasattr(n, 'parent'):
            n, n_child = n.parent, n
            if isinstance(n, LOOP_TYPES):
                # Doesn't apply unless it's in the loop itself
                if n_child not in n.orelse:
                    return
            if isinstance(n, (ast.FunctionDef, ast.ClassDef)):
                break
            # Handle Try/TryFinally difference in Python < and >= 3.3
            if hasattr(n, 'finalbody') and isinstance(node, ast.Continue):
                if n_child in n.finalbody:
                    self.report(messages.ContinueInFinally, node)
                    return
        if isinstance(node, ast.Continue):
            self.report(messages.ContinueOutsideLoop, node)
        else:  # ast.Break
            self.report(messages.BreakOutsideLoop, node) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:24,代码来源:checker.py

示例2: visit_classdef

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import ClassDef [as 别名]
def visit_classdef(self, node: _ast.ClassDef):
        raise BadSyntax('Defining new class via def syntax is not allowed') 
开发者ID:item4,项目名称:yui,代码行数:4,代码来源:calc.py

示例3: get_content

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import ClassDef [as 别名]
def get_content(filename=None):
    """
    get_content generates sections or examples out of the given file path.
    """
    log.info("Parsing content.")
    if filename is None:
        filename = CONTENT_MODULE_PATH
    with open(str(filename), encoding='utf-8') as fp:
        source = fp.read()
        module = ast.parse(source)
        for node in module.body:
            if isinstance(node, _ast.FunctionDef) and node.name.startswith('test_'):
                yield parse_function(node)
            if isinstance(node, _ast.ClassDef) and node.name.startswith('Test'):
                yield parse_class(node) 
开发者ID:ulope,项目名称:pyformat.info,代码行数:17,代码来源:main.py


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