本文整理汇总了Python中lib2to3.fixer_util.syms.dictsetmaker方法的典型用法代码示例。如果您正苦于以下问题:Python syms.dictsetmaker方法的具体用法?Python syms.dictsetmaker怎么用?Python syms.dictsetmaker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib2to3.fixer_util.syms
的用法示例。
在下文中一共展示了syms.dictsetmaker方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _IsDictListTupleDelimiterTok
# 需要导入模块: from lib2to3.fixer_util import syms [as 别名]
# 或者: from lib2to3.fixer_util.syms import dictsetmaker [as 别名]
def _IsDictListTupleDelimiterTok(tok, is_opening):
assert tok
if tok.matching_bracket is None:
return False
if is_opening:
open_tok = tok
close_tok = tok.matching_bracket
else:
open_tok = tok.matching_bracket
close_tok = tok
# There must be something in between the tokens
if open_tok.next_token == close_tok:
return False
assert open_tok.next_token.node
assert open_tok.next_token.node.parent
return open_tok.next_token.node.parent.type in [
python_symbols.dictsetmaker,
python_symbols.listmaker,
python_symbols.testlist_gexp,
]
示例2: transform
# 需要导入模块: from lib2to3.fixer_util import syms [as 别名]
# 或者: from lib2to3.fixer_util.syms import dictsetmaker [as 别名]
def transform(self, node, results):
single = results.get("single")
if single:
# Make a fake listmaker
fake = pytree.Node(syms.listmaker, [single.clone()])
single.replace(fake)
items = fake
else:
items = results["items"]
# Build the contents of the literal
literal = [pytree.Leaf(token.LBRACE, "{")]
literal.extend(n.clone() for n in items.children)
literal.append(pytree.Leaf(token.RBRACE, "}"))
# Set the prefix of the right brace to that of the ')' or ']'
literal[-1].prefix = items.next_sibling.prefix
maker = pytree.Node(syms.dictsetmaker, literal)
maker.prefix = node.prefix
# If the original was a one tuple, we need to remove the extra comma.
if len(maker.children) == 4:
n = maker.children[2]
n.remove()
maker.children[-1].prefix = n.prefix
# Finally, replace the set call with our shiny new literal.
return maker
示例3: transform
# 需要导入模块: from lib2to3.fixer_util import syms [as 别名]
# 或者: from lib2to3.fixer_util.syms import dictsetmaker [as 别名]
def transform(self, node, results):
single = results.get("single")
if single:
# Make a fake listmaker
fake = pytree.Node(syms.listmaker, [single.clone()])
single.replace(fake)
items = fake
else:
items = results["items"]
# Build the contents of the literal
literal = [pytree.Leaf(token.LBRACE, u"{")]
literal.extend(n.clone() for n in items.children)
literal.append(pytree.Leaf(token.RBRACE, u"}"))
# Set the prefix of the right brace to that of the ')' or ']'
literal[-1].prefix = items.next_sibling.prefix
maker = pytree.Node(syms.dictsetmaker, literal)
maker.prefix = node.prefix
# If the original was a one tuple, we need to remove the extra comma.
if len(maker.children) == 4:
n = maker.children[2]
n.remove()
maker.children[-1].prefix = n.prefix
# Finally, replace the set call with our shiny new literal.
return maker