本文整理汇总了Python中symbol.classdef方法的典型用法代码示例。如果您正苦于以下问题:Python symbol.classdef方法的具体用法?Python symbol.classdef怎么用?Python symbol.classdef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类symbol
的用法示例。
在下文中一共展示了symbol.classdef方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compile_node
# 需要导入模块: import symbol [as 别名]
# 或者: from symbol import classdef [as 别名]
def compile_node(self, node):
### emit a line-number node?
n = node[0]
if n == symbol.encoding_decl:
self.encoding = node[2]
node = node[1]
n = node[0]
if n == symbol.single_input:
return self.single_input(node[1:])
if n == symbol.file_input:
return self.file_input(node[1:])
if n == symbol.eval_input:
return self.eval_input(node[1:])
if n == symbol.lambdef:
return self.lambdef(node[1:])
if n == symbol.funcdef:
return self.funcdef(node[1:])
if n == symbol.classdef:
return self.classdef(node[1:])
raise WalkerError, ('unexpected node type', n)
示例2: classdef
# 需要导入模块: import symbol [as 别名]
# 或者: from symbol import classdef [as 别名]
def classdef(self, nodelist):
# classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
name = nodelist[1][1]
doc = self.get_docstring(nodelist[-1])
if nodelist[2][0] == token.COLON:
bases = []
elif nodelist[3][0] == token.RPAR:
bases = []
else:
bases = self.com_bases(nodelist[3])
# code for class
code = self.com_node(nodelist[-1])
if doc is not None:
assert isinstance(code, Stmt)
assert isinstance(code.nodes[0], Discard)
del code.nodes[0]
return Class(name, bases, doc, code, lineno=nodelist[1][2])
示例3: _extract_info
# 需要导入模块: import symbol [as 别名]
# 或者: from symbol import classdef [as 别名]
def _extract_info(self, tree):
# extract docstring
if len(tree) == 2:
found, vars = match(DOCSTRING_STMT_PATTERN[1], tree[1])
else:
found, vars = match(DOCSTRING_STMT_PATTERN, tree[3])
if found:
self._docstring = eval(vars['docstring'])
# discover inner definitions
for node in tree[1:]:
found, vars = match(COMPOUND_STMT_PATTERN, node)
if found:
cstmt = vars['compound']
if cstmt[0] == symbol.funcdef:
name = cstmt[2][1]
self._function_info[name] = FunctionInfo(cstmt)
elif cstmt[0] == symbol.classdef:
name = cstmt[2][1]
self._class_info[name] = ClassInfo(cstmt)
示例4: Annotate
# 需要导入模块: import symbol [as 别名]
# 或者: from symbol import classdef [as 别名]
def Annotate(cls, symbol_type, children):
if symbol_type != symbol.stmt:
return None
compound_statement = children[0]
if compound_statement.type != symbol.compound_stmt:
return None
statement = compound_statement.children[0]
if statement.type == symbol.classdef:
return cls(statement.type, statement.children)
elif (statement.type == symbol.decorated and
statement.children[-1].type == symbol.classdef):
return cls(statement.type, statement.children)
else:
return None
示例5: decorated
# 需要导入模块: import symbol [as 别名]
# 或者: from symbol import classdef [as 别名]
def decorated(self, nodelist):
assert nodelist[0][0] == symbol.decorators
if nodelist[1][0] == symbol.funcdef:
n = [nodelist[0]] + list(nodelist[1][1:])
return self.funcdef(n)
elif nodelist[1][0] == symbol.classdef:
decorators = self.decorators(nodelist[0][1:])
cls = self.classdef(nodelist[1][1:])
cls.decorators = decorators
return cls
raise WalkerError()
示例6: _get_forbidden_symbols
# 需要导入模块: import symbol [as 别名]
# 或者: from symbol import classdef [as 别名]
def _get_forbidden_symbols():
"""
Returns a list of symbol codes representing statements that are *not*
wanted in configuration files.
"""
try:
# Python 2.5:
symlst = [symbol.break_stmt, symbol.classdef, symbol.continue_stmt,
symbol.decorator, symbol.decorators, symbol.eval_input,
symbol.except_clause, symbol.exec_stmt, symbol.flow_stmt,
symbol.for_stmt, symbol.fpdef, symbol.fplist, symbol.funcdef,
symbol.global_stmt, symbol.import_as_name, symbol.import_as_names,
symbol.import_from, symbol.import_name, symbol.import_stmt,
symbol.lambdef, symbol.old_lambdef, symbol.print_stmt,
symbol.raise_stmt, symbol.try_stmt, symbol.while_stmt,
symbol.with_stmt, symbol.with_var, symbol.yield_stmt,
symbol.yield_expr]
except AttributeError:
# Python 2.4:
symlst = [symbol.break_stmt, symbol.classdef, symbol.continue_stmt,
symbol.decorator, symbol.decorators, symbol.eval_input,
symbol.except_clause, symbol.exec_stmt, symbol.flow_stmt,
symbol.for_stmt, symbol.fpdef, symbol.fplist, symbol.funcdef,
symbol.global_stmt, symbol.import_as_name, symbol.import_as_names,
symbol.import_from, symbol.import_name, symbol.import_stmt,
symbol.lambdef, symbol.print_stmt, symbol.raise_stmt,
symbol.try_stmt, symbol.while_stmt]
return symlst