当前位置: 首页>>代码示例>>Python>>正文


Python syms.dictsetmaker方法代码示例

本文整理汇总了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,
  ] 
开发者ID:google,项目名称:yapf,代码行数:27,代码来源:unwrapped_line.py

示例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 
开发者ID:remg427,项目名称:misp42splunk,代码行数:29,代码来源:fix_set_literal.py

示例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 
开发者ID:remg427,项目名称:misp42splunk,代码行数:29,代码来源:fix_set_literal.py


注:本文中的lib2to3.fixer_util.syms.dictsetmaker方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。