本文整理匯總了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)