How to use parso - 10 common examples

To help you get started, we’ve selected a few parso 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 davidhalter / parso / test / test_get_code.py View on Github external
while hasattr(self, 'xy'):
            yield True
        for x in [1, 2]:
            yield x
    def empty(self):
        pass
class Empty:
    pass
class WithDocstring:
    """class docstr"""
    pass
def method_with_docstring():
    """class docstr"""
    pass
'''
    assert parse(s).get_code() == s
github boxed / mutmut / tests / test_mutation.py View on Github external
def test_matches_py3():
    node = parse('a: Optional[int] = 7\n').children[0].children[0].children[1].children[1].children[1].children[1]
    assert not array_subscript_pattern.matches(node=node)
github davidhalter / parso / test / test_parser.py View on Github external
def get_sub(source):
        return parse(source, version=each_version).children[0]
github davidhalter / parso / test / test_error_recovery.py View on Github external
def test_one_line_function(each_version):
    module = parse('def x(): f.', version=each_version)
    assert module.children[0].type == 'funcdef'
    def_, name, parameters, colon, f = module.children[0].children
    assert f.type == 'error_node'

    module = parse('def x(a:', version=each_version)
    func = module.children[0]
    assert func.type == 'error_node'
    if each_version.startswith('2'):
        assert func.children[-1].value == 'a'
    else:
        assert func.children[-1] == ':'
github davidhalter / parso / test / test_prefix.py View on Github external
def test_utf8_bom():
    tree = parso.parse(unicode_bom + 'a = 1')
    expr_stmt = tree.children[0]
    assert expr_stmt.start_pos == (1, 0)

    tree = parso.parse(unicode_bom + '\n')
    endmarker = tree.children[0]
    parts = list(endmarker._split_prefix())
    assert [p.type for p in parts] == ['bom', 'newline', 'spacing']
    assert [p.start_pos for p in parts] == [(1, 0), (1, 0), (2, 0)]
    assert [p.end_pos for p in parts] == [(1, 0), (2, 0), (2, 0)]
github davidhalter / parso / test / test_tokenize.py View on Github external
def test_tokenize_multiline_II():
    # Make sure multiline string having no newlines have the end marker on
    # same line
    fundef = '''""""'''
    token_list = _get_token_list(fundef)
    assert token_list == [PythonToken(ERRORTOKEN, '""""', (1, 0), ''),
                          PythonToken(ENDMARKER,      '', (1, 4), '')]
github davidhalter / parso / test / test_pgen2.py View on Github external
def _parse(code, version=None):
    code = dedent(code) + "\n\n"
    grammar = load_grammar(version=version)
    return grammar.parse(code, error_recovery=False)
github davidhalter / parso / test / test_python_errors.py View on Github external
def _get_error_list(code, version=None):
    grammar = parso.load_grammar(version=version)
    tree = grammar.parse(code)
    return list(grammar.iter_errors(tree))
github davidhalter / parso / test / test_pep8.py View on Github external
def issues(code):
    grammar = parso.load_grammar()
    module = parso.parse(code)
    return grammar._get_normalizer_issues(module)
github davidhalter / jedi / test / test_parso_integration / test_parser_utils.py View on Github external
def test_call_type(self):
        call = self.get_call('hello')
        assert isinstance(call, tree.Name)