diff --git a/jedi/parser/fast.py b/jedi/parser/fast.py index 24ea6521..242a006f 100644 --- a/jedi/parser/fast.py +++ b/jedi/parser/fast.py @@ -16,7 +16,7 @@ from jedi.parser.tokenize import (source_tokens, FLOWS, NEWLINE, ENDMARKER, INDENT, DEDENT) -class FastModule(pr.Module, pr.Simple): +class FastModule(pr.SubModule): type = 'file_input' def __init__(self): @@ -48,13 +48,6 @@ class FastModule(pr.Module, pr.Simple): """ return MergedNamesDict([m.used_names for m in self.modules]) - def _search_in_scope(self, typ): - return pr.Scope._search_in_scope(self, typ) - - @property - def subscopes(self): - return self._search_in_scope(pr.Scope) - def __repr__(self): return "" % (type(self).__name__, self.name, self.start_pos[0], self.end_pos[0]) @@ -556,7 +549,7 @@ class FastTokenizer(object): if self._parentheses_level: # Parentheses ignore the indentation rules. pass - elif indent < self._parser_indent: # -> dedent + elif False and indent < self._parser_indent: # -> dedent raise NotImplementedError self._parser_indent = indent self._new_indent = False @@ -574,18 +567,18 @@ class FastTokenizer(object): if self._in_flow: print('INFLOW', self._indent_counter) self._flow_indent_counter = self._indent_counter - self._old_parser_indent = self._parser_indent - self._parser_indent += 1 # new scope: must be higher - self._new_indent = True + #self._old_parser_indent = self._parser_indent + #self._parser_indent += 1 # new scope: must be higher + #self._new_indent = True elif value in breaks: if not self._is_decorator: return self._close() self._is_decorator = '@' == value - if not self._is_decorator: - self._old_parser_indent = self._parser_indent - self._parser_indent += 1 # new scope: must be higher - self._new_indent = True + #if not self._is_decorator: + #self._old_parser_indent = self._parser_indent + #self._parser_indent += 1 # new scope: must be higher + #self._new_indent = True if value != '@': if self._first_stmt and not self._new_indent: diff --git a/jedi/parser/grammar2.7.txt b/jedi/parser/grammar2.7.txt index 6febbb4f..2dea5140 100644 --- a/jedi/parser/grammar2.7.txt +++ b/jedi/parser/grammar2.7.txt @@ -97,7 +97,9 @@ with_item: test ['as' expr] with_var: 'as' expr # NB compile.c makes sure that the default except clause is last except_clause: 'except' [test [(',' | 'as') test]] -suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT +# Edit by David Halter: The stmt is now optional. This reflects how Jedi allows +# classes and functions to be empty, which is beneficial for autocompletion. +suite: simple_stmt | NEWLINE INDENT stmt* DEDENT # Backward compatibility cruft to support: # [ x for x in lambda: True, lambda: False if x() ] diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index e43a6fd9..90672057 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -533,7 +533,6 @@ class Scope(Simple, DocstringMixin): def imports(self): return self._search_in_scope(Import) - @Python3Method def _search_in_scope(self, typ): def scan(children): elements = [] diff --git a/test/test_parser/test_fast_parser.py b/test/test_parser/test_fast_parser.py index e2d2b3d4..60fdc129 100644 --- a/test/test_parser/test_fast_parser.py +++ b/test/test_parser/test_fast_parser.py @@ -113,14 +113,15 @@ def test_if(): x = 3 if x: def y(): - x - x = 3 + return x + return y() - pass + func() ''') # Two parsers needed, one for pass and one for the function. check_fp(src, 2) + assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int'] def test_incomplete_function():