How to use darglint - 10 common examples

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_parser.py View on Github external
def test_only_indents_treated_newlines_within_simple_section(self):
        """Make sure indent-only lines are treated as newlines in simple."""
        node = parse(condense(lex('\n'.join([
            'Get the value of pi.',
            '',
            'Returns:',
            '    A value that is an approximation of pi.  This approximation',
            '    is actually just the quotient,',
            '    ',
            'Raises:',
            '    Exception: Seemingly at random.',
        ]))))
        self.assertTrue(CykNodeUtils.contains(node, 'raises-section'))
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_noqa_for_argument(self):
        func = '\n'.join([
            'def my_function():',
            '    """Has an extra argument, but thats okay.',
            '',
            '    Args:',
            '        arg1: This will be defined very soon.  # noqa: I102',
            '',
            '    """',
            '    print("Not done yet!")',
        ])
        doc = ast.get_docstring(ast.parse(func).body[0])
        self.assertTrue(doc.startswith('Has an extra'))
        node = parse(condense(lex(doc)))
        self.assertTrue(
            CykNodeUtils.contains(node, 'noqa'),
        )
        noqa = self.get_identifier(node, NoqaIdentifier)
        self.assertTrue(
            noqa is not None,
        )
        self.assertEqual(
            NoqaIdentifier.extract(noqa),
            'I102',
        )
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_empty_line(self):
        """Make sure we can parse a line with just an indent."""
        node = parse(condense(lex(' '*4 + '\n')))
        self.assertTrue(node)
github terrencepreilly / darglint / tests / test_new_parse.py View on Github external
def test_parse_item(self):
        """Make sure we can parse the parts of a compound section."""
        node = parse_item(Peaker(lex(
            '    x (int): The first number\n'
            '        to add\n'
        ), lookahead=3))
        self.assertEqual(
            node.node_type,
            NodeType.ITEM,
        )
        child_types = [x.node_type for x in node.walk()]
        self.assertEqual(
            child_types,
            [
                NodeType.INDENT,
                NodeType.WORD,
                NodeType.LPAREN,
                NodeType.WORD,
                NodeType.RPAREN,
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_type_with_colon_in_yields(self):
        docstring = '\n'.join([
            'Get the nodes in the tree.',
            '',
            'Yields:',
            '    Node: The nodes in the tree.',
        ])
        tokens = condense(lex(docstring))
        tree = parse(tokens)
        self.assertTrue(tree is not None)
        self.assertContains(tree, 'yields-type')
github terrencepreilly / darglint / tests / test_sphinx_parser.py View on Github external
def test_parse_short_description_one_word_cyk(self):
        """Make sure a single word can suffice."""
        content = 'Kills.'
        node = parse(condense(lex(content)))
        self.assertTrue(CykNodeUtils.contains(node, 'short-description'))
github terrencepreilly / darglint / tests / test_sphinx_parser.py View on Github external
'key', 'keyword',
                'var', 'ivar', 'cvar',
            ],
            'argument-type-section': ['type'],
            'variable-type-section': ['vartype'],
            'raises-section': ['raises'],
            # 'returns-section': ['returns'],
            # 'return-type-section': ['rtype'],
            'yields-section': ['yield', 'yields'],
        }
        for keyword_section in keywords:
            for keyword in keywords[keyword_section]:
                docstring = 'Short description.\n\n:{} a: something'.format(
                    keyword,
                )
                node = parse(condense(lex(docstring)))
                self.assertTrue(
                    CykNodeUtils.contains(node, keyword_section),
                    '{}: {}'.format(keyword_section, node)
                )
github terrencepreilly / darglint / tests / test_sphinx_parser.py View on Github external
def test_parser_sections_correctly(self):
        program = '\n'.join([
            'def func(x, l):',
            '    """Add an item to the head of the list.',
            '    ',
            '    :param x: The item to add to the list.',
            '    :return: The list with the item attached.',
            '    ',
            '    """',
            '    return l.appendleft(x)',
        ])
        doc = ast.get_docstring(ast.parse(program).body[0])
        tokens = condense(lex(doc))
        node = parse(tokens)
        self.assertTrue(
            CykNodeUtils.contains(node, 'returns-section'),
        )
        self.assertTrue(
            CykNodeUtils.contains(node, 'arguments-section'),
        )
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_star_arguments(self):
        docstring = '\n'.join([
            'Negate a function which returns a boolean.',
            '',
            'Args:',
            '    *fns (int): Functions which returns a boolean.',
            '',
            'Returns:',
            '    int: A function which returns fallse when any of the'
            '        callables return true, and true will all of the ',
            '        callables return false.',
        ])
        tokens = condense(lex(docstring))
        tree = parse(tokens)
        self.assertTrue(tree is not None)
        self.assertContains(tree, 'arguments')
github terrencepreilly / darglint / tests / test_sphinx_parser.py View on Github external
def test_parse_whole_docstring_cyk(self):
        """Make sure we can parse a whole docstring."""
        node = parse(condense(lex('\n'.join([
            'Format the exception with a traceback.',
            '',
            ':param etype: exception type',
            ':param value: exception value',
            ':param tb: traceback object',
            ':param limit: maximum number of stack frames to show',
            ':type limit: integer or None',
            ':rtype: list of strings',
        ]))))
        for section in [
            'arguments-section',
            'argument-type-section',
            'return-type-section',
        ]:
            self.assertTrue(CykNodeUtils.contains(node, section), node)