From 27f05de3b7c64e06814602589455657b6028c77f Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 13 Jun 2016 18:21:17 +0200 Subject: [PATCH] Fix a few more issues, mostly with the fast parser. --- jedi/evaluate/__init__.py | 4 +++- jedi/parser/__init__.py | 1 + jedi/parser/fast.py | 7 +++++-- test/test_parser/test_fast_parser.py | 10 ++++++++++ test/test_regression.py | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index ed426801..1c569007 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -442,13 +442,15 @@ class Evaluator(object): def_ = name.get_definition() is_simple_name = name.parent.type not in ('power', 'trailer') if is_simple_name: + if name.parent.type in ('file_input', 'classdef', 'funcdef'): + return [self.wrap(name.parent)] if def_.type == 'expr_stmt' and name in def_.get_defined_names(): return self.eval_statement(def_, name) elif def_.type == 'for_stmt': container_types = self.eval_element(def_.children[3]) for_types = iterable.py__iter__types(self, container_types, def_.children[3]) return finder.check_tuple_assignments(self, for_types, name) - elif def_.type == 'import_from': + elif def_.type in ('import_from', 'import_name'): return imports.ImportWrapper(self, name).follow() call = helpers.call_of_name(name) diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 1a8f8d52..6f6bbfe3 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -191,6 +191,7 @@ class Parser(object): self.remove_last_newline() def get_parsed_node(self): + # TODO rename to get_root_node return self._parsed def _tokenize(self, tokenizer): diff --git a/jedi/parser/fast.py b/jedi/parser/fast.py index 058a957c..af372542 100644 --- a/jedi/parser/fast.py +++ b/jedi/parser/fast.py @@ -259,6 +259,9 @@ class FastParser(use_metaclass(CachedFastParser)): self.module = FastModule(self.module_path) self.root_node = self.current_node = ParserNode(self.module, self, '') + def get_parsed_node(self): + return self.module + def update(self, source): # Variables for testing purposes: It is important that the number of # parsers used can be minimized. With these variables we can test @@ -326,13 +329,13 @@ class FastParser(use_metaclass(CachedFastParser)): current_lines.append(l) # Just ignore comments and blank lines continue - if new_indent: + if new_indent and not parentheses_level: if indent > indent_list[-2]: # Set the actual indent, not just the random old indent + 1. indent_list[-1] = indent new_indent = False - while indent <= indent_list[-2]: # -> dedent + while indent < indent_list[-1]: # -> dedent indent_list.pop() # This automatically resets the flow_indent if there was a # dedent or a flow just on one line (with one simple_stmt). diff --git a/test/test_parser/test_fast_parser.py b/test/test_parser/test_fast_parser.py index 147ac488..607fae07 100644 --- a/test/test_parser/test_fast_parser.py +++ b/test/test_parser/test_fast_parser.py @@ -469,3 +469,13 @@ def test_decorator_string_issue(): s = jedi.Script(source) assert s.completions() assert s._parser.module().get_code() == source + + +def test_round_trip(): + source = dedent(''' + def x(): + """hahaha""" + func''') + + f = FastParser(load_grammar(), source) + assert f.get_parsed_node().get_code() == source diff --git a/test/test_regression.py b/test/test_regression.py index 9ddfb381..68573031 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -146,7 +146,7 @@ class TestRegression(TestCase): x = 0 a = \ [1, 2, 3, 4, 5, 6, 7, 8, 9, (x)] # <-- here - """, '(x)] # <-- here', []) + """, '(x)] # <-- here', ['int']) def test_generator(self): # Did have some problems with the usage of generator completions this