How to use the darglint.node.CykNode function in darglint

To help you get started, we’ve selected a few darglint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terrencepreilly / darglint / tests / test_identifiers.py View on Github external
def _l(node):
    return CykNode(
        'left',
        lchild=node,
    )
github terrencepreilly / darglint / tests / test_node.py View on Github external
def build_binary_search_tree(self, root, value):
        if value < root.value:
            if not root.lchild:
                root.lchild = CykNode(symbol='', value=value)
            else:
                self.build_binary_search_tree(root.lchild, value)
        elif value > root.value:
            if not root.rchild:
                root.rchild = CykNode(symbol='', value=value)
            else:
                self.build_binary_search_tree(root.rchild, value)
        else:
            pass
github terrencepreilly / darglint / darglint / parse / google.py View on Github external
return CykNode(
                symbol='docstring',
                lchild=nodes[0],
            )
        elif len(nodes) == 2:
            return CykNode(
                symbol='docstring',
                lchild=nodes[0],
                rchild=nodes[1],
            )
    if args:
        return reduce(inner, args)
    else:
        # The arguments are empty, so we return an
        # empty docstring.
        return CykNode(symbol='docstring')
github terrencepreilly / darglint / darglint / parse / long_description.py View on Github external
def _parse_noqa(peaker):
    # type: (Peaker[Token]) -> Optional[CykNode]
    if not (
        _are(peaker, TokenType.HASH, TokenType.NOQA, TokenType.COLON,
             TokenType.WORD)
    ):
        return None
    noqa_hash = CykNode('hash', value=peaker.next())
    noqa = CykNode('noqa', value=peaker.next())
    colon = CykNode('colon', value=peaker.next())
    targets = _parse_words_until_newline_or_end(peaker)
    head = CykNode(
        'noqa',
        lchild=CykNode(
            'noqa-head',
            lchild=noqa_hash,
            rchild=noqa,
        ),
        rchild=CykNode(
            'noqa-statement1',
            lchild=colon,
            rchild=targets,
        ),
        annotations=[
github terrencepreilly / darglint / darglint / parse / long_description.py View on Github external
def _parse_words_until_newline_or_end(peaker):
    if not peaker.has_next() or _is(peaker, TokenType.NEWLINE):
        return None
    words = [CykNode('word', value=peaker.next())]
    while peaker.has_next() and not _is(peaker, TokenType.NEWLINE):
        words.append(CykNode('word', value=peaker.next()))

    if len(words) == 1:
        head = words[0]
        head.symbol = 'words'
        return head

    def join(x, y):
        return CykNode(
            'words',
            lchild=x,
            rchild=y,
        )

    acc = words.pop()
    acc.symbol = 'words'
github terrencepreilly / darglint / darglint / parse / numpy.py View on Github external
def inner(*nodes):
        if len(nodes) == 1:
            return CykNode(
                symbol='docstring',
                lchild=nodes[0],
            )
        elif len(nodes) == 2:
            return CykNode(
                symbol='docstring',
                lchild=nodes[0],
                rchild=nodes[1],
            )
github terrencepreilly / darglint / darglint / parse / cyk.py View on Github external
for p in range(l):
                for a, production in enumerate(grammar.productions):
                    for derivation in production.rhs:
                        is_terminal_derivation = len(derivation) <= 2
                        if is_terminal_derivation:
                            continue
                        annotations, B, C, weight = derivation
                        b = lookup[B]
                        c = lookup[C]
                        lchild = P[p - 1][s - 1][b]
                        rchild = P[l - p - 1][s + p - 1][c]
                        if lchild and rchild:
                            old = P[l - 1][s - 1][a]
                            if old and old.weight > weight:
                                continue
                            P[l - 1][s - 1][a] = CykNode(
                                production.lhs,
                                lchild,
                                rchild,
                                annotations=annotations,
                                weight=weight,
                            )
    return P[n - 1][0][lookup[grammar.start]]
github terrencepreilly / darglint / darglint / parse / numpy.py View on Github external
return CykNode(
                symbol='docstring',
                lchild=nodes[0],
            )
        elif len(nodes) == 2:
            return CykNode(
                symbol='docstring',
                lchild=nodes[0],
                rchild=nodes[1],
            )
    if args:
        return reduce(inner, args)
    else:
        # The arguments are empty, so we return an
        # empty docstring.
        return CykNode(symbol='docstring')
github terrencepreilly / darglint / darglint / parse / long_description.py View on Github external
def _parse_noqa(peaker):
    # type: (Peaker[Token]) -> Optional[CykNode]
    if not (
        _are(peaker, TokenType.HASH, TokenType.NOQA, TokenType.COLON,
             TokenType.WORD)
    ):
        return None
    noqa_hash = CykNode('hash', value=peaker.next())
    noqa = CykNode('noqa', value=peaker.next())
    colon = CykNode('colon', value=peaker.next())
    targets = _parse_words_until_newline_or_end(peaker)
    head = CykNode(
        'noqa',
        lchild=CykNode(
            'noqa-head',
            lchild=noqa_hash,
            rchild=noqa,
        ),
        rchild=CykNode(
            'noqa-statement1',
            lchild=colon,
            rchild=targets,
        ),
        annotations=[
            NoqaIdentifier,
github terrencepreilly / darglint / darglint / docstring / google.py View on Github external
def __init__(self, root, style=DocstringStyle.GOOGLE):
        # type: (Union[CykNode, str], DocstringStyle) -> None
        """Create a new docstring from the AST.

        Args:
            root: The root of the AST, or the docstring
                (as a string.)  If it is a string, the
                string will be parsed.
            style: The style of the docstring.  Discarded,
                since this Docstring is always the Google style.

        """
        if isinstance(root, CykNode):
            self.root = root
        else:
            self.root = parse(condense(lex(root)))
        self._lookup = self._discover()