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


Python pytree.Base方法代碼示例

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


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

示例1: test_instantiate_base

# 需要導入模塊: from lib2to3 import pytree [as 別名]
# 或者: from lib2to3.pytree import Base [as 別名]
def test_instantiate_base(self):
        if __debug__:
            # Test that instantiating Base() raises an AssertionError
            self.assertRaises(AssertionError, pytree.Base) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:6,代碼來源:test_pytree.py

示例2: count_args

# 需要導入模塊: from lib2to3 import pytree [as 別名]
# 或者: from lib2to3.pytree import Base [as 別名]
def count_args(node, results):
    # type: (Node, Dict[str, Base]) -> Tuple[int, bool, bool, bool]
    """Count arguments and check for self and *args, **kwds.

    Return (selfish, count, star, starstar) where:
    - count is total number of args (including *args, **kwds)
    - selfish is True if the initial arg is named 'self' or 'cls'
    - star is True iff *args is found
    - starstar is True iff **kwds is found
    """
    count = 0
    selfish = False
    star = False
    starstar = False
    args = results.get('args')
    if isinstance(args, Node):
        children = args.children
    elif isinstance(args, Leaf):
        children = [args]
    else:
        children = []
    # Interpret children according to the following grammar:
    # (('*'|'**')? NAME ['=' expr] ','?)*
    skip = False
    previous_token_is_star = False
    for child in children:
        if skip:
            skip = False
        elif isinstance(child, Leaf):
            # A single '*' indicates the rest of the arguments are keyword only
            # and shouldn't be counted as a `*`.
            if child.type == token.STAR:
                previous_token_is_star = True
            elif child.type == token.DOUBLESTAR:
                starstar = True
            elif child.type == token.NAME:
                if count == 0:
                    if child.value in ('self', 'cls'):
                        selfish = True
                count += 1
                if previous_token_is_star:
                    star = True
            elif child.type == token.EQUAL:
                skip = True
            if child.type != token.STAR:
                previous_token_is_star = False
    return count, selfish, star, starstar 
開發者ID:dropbox,項目名稱:pyannotate,代碼行數:49,代碼來源:fix_annotate_json.py


注:本文中的lib2to3.pytree.Base方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。