本文整理汇总了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)
示例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')
示例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)