本文整理汇总了Python中compiler.ast.Keyword方法的典型用法代码示例。如果您正苦于以下问题:Python ast.Keyword方法的具体用法?Python ast.Keyword怎么用?Python ast.Keyword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类compiler.ast
的用法示例。
在下文中一共展示了ast.Keyword方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visitCallFunc
# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Keyword [as 别名]
def visitCallFunc(self, node):
pos = 0
kw = 0
self.set_lineno(node)
self.visit(node.node)
for arg in node.args:
self.visit(arg)
if isinstance(arg, ast.Keyword):
kw = kw + 1
else:
pos = pos + 1
if node.star_args is not None:
self.visit(node.star_args)
if node.dstar_args is not None:
self.visit(node.dstar_args)
have_star = node.star_args is not None
have_dstar = node.dstar_args is not None
opcode = callfunc_opcode_info[have_star, have_dstar]
self.emit(opcode, kw << 8 | pos)
示例2: deprecatedToUsefulText
# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Keyword [as 别名]
def deprecatedToUsefulText(name, deprecated):
"""
Change a C{@deprecated} to a display string.
"""
from twisted.python.deprecate import _getDeprecationWarningString
version = versionToUsefulObject(deprecated[1])
if deprecated[2]:
if isinstance(deprecated[2], ast.Keyword):
replacement = deprecated[2].asList()[1].value
else:
replacement = deprecated[2].value
else:
replacement = None
return _getDeprecationWarningString(name, version, replacement=replacement) + "."
示例3: eval
# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Keyword [as 别名]
def eval(self, frame):
node = Interpretable(self.node)
node.eval(frame)
explanations = []
vars = {'__exprinfo_fn': node.result}
source = '__exprinfo_fn('
for a in self.args:
if isinstance(a, ast.Keyword):
keyword = a.name
a = a.expr
else:
keyword = None
a = Interpretable(a)
a.eval(frame)
argname = '__exprinfo_%d' % len(vars)
vars[argname] = a.result
if keyword is None:
source += argname + ','
explanations.append(a.explanation)
else:
source += '%s=%s,' % (keyword, argname)
explanations.append('%s=%s' % (keyword, a.explanation))
if self.star_args:
star_args = Interpretable(self.star_args)
star_args.eval(frame)
argname = '__exprinfo_star'
vars[argname] = star_args.result
source += '*' + argname + ','
explanations.append('*' + star_args.explanation)
if self.dstar_args:
dstar_args = Interpretable(self.dstar_args)
dstar_args.eval(frame)
argname = '__exprinfo_kwds'
vars[argname] = dstar_args.result
source += '**' + argname + ','
explanations.append('**' + dstar_args.explanation)
self.explanation = "%s(%s)" % (
node.explanation, ', '.join(explanations))
if source.endswith(','):
source = source[:-1]
source += ')'
try:
self.result = frame.eval(source, **vars)
except passthroughex:
raise
except:
raise Failure(self)
if not node.is_builtin(frame) or not self.is_bool(frame):
r = frame.repr(self.result)
self.explanation = '%s\n{%s = %s\n}' % (r, r, self.explanation)