當前位置: 首頁>>代碼示例>>Python>>正文


Python syms.listmaker方法代碼示例

本文整理匯總了Python中lib2to3.fixer_util.syms.listmaker方法的典型用法代碼示例。如果您正苦於以下問題:Python syms.listmaker方法的具體用法?Python syms.listmaker怎麽用?Python syms.listmaker使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在lib2to3.fixer_util.syms的用法示例。


在下文中一共展示了syms.listmaker方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _IsDictListTupleDelimiterTok

# 需要導入模塊: from lib2to3.fixer_util import syms [as 別名]
# 或者: from lib2to3.fixer_util.syms import listmaker [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 listmaker [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 listmaker [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.listmaker方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。