FastModule should inherit from SubModule, because it has almost all the same properties.

This commit is contained in:
Dave Halter
2015-01-28 14:59:00 +01:00
parent 6ec89e6785
commit d0589430bb
4 changed files with 16 additions and 21 deletions

View File

@@ -16,7 +16,7 @@ from jedi.parser.tokenize import (source_tokens, FLOWS, NEWLINE,
ENDMARKER, INDENT, DEDENT) ENDMARKER, INDENT, DEDENT)
class FastModule(pr.Module, pr.Simple): class FastModule(pr.SubModule):
type = 'file_input' type = 'file_input'
def __init__(self): def __init__(self):
@@ -48,13 +48,6 @@ class FastModule(pr.Module, pr.Simple):
""" """
return MergedNamesDict([m.used_names for m in self.modules]) 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): def __repr__(self):
return "<fast.%s: %s@%s-%s>" % (type(self).__name__, self.name, return "<fast.%s: %s@%s-%s>" % (type(self).__name__, self.name,
self.start_pos[0], self.end_pos[0]) self.start_pos[0], self.end_pos[0])
@@ -556,7 +549,7 @@ class FastTokenizer(object):
if self._parentheses_level: if self._parentheses_level:
# Parentheses ignore the indentation rules. # Parentheses ignore the indentation rules.
pass pass
elif indent < self._parser_indent: # -> dedent elif False and indent < self._parser_indent: # -> dedent
raise NotImplementedError raise NotImplementedError
self._parser_indent = indent self._parser_indent = indent
self._new_indent = False self._new_indent = False
@@ -574,18 +567,18 @@ class FastTokenizer(object):
if self._in_flow: if self._in_flow:
print('INFLOW', self._indent_counter) print('INFLOW', self._indent_counter)
self._flow_indent_counter = self._indent_counter self._flow_indent_counter = self._indent_counter
self._old_parser_indent = self._parser_indent #self._old_parser_indent = self._parser_indent
self._parser_indent += 1 # new scope: must be higher #self._parser_indent += 1 # new scope: must be higher
self._new_indent = True #self._new_indent = True
elif value in breaks: elif value in breaks:
if not self._is_decorator: if not self._is_decorator:
return self._close() return self._close()
self._is_decorator = '@' == value self._is_decorator = '@' == value
if not self._is_decorator: #if not self._is_decorator:
self._old_parser_indent = self._parser_indent #self._old_parser_indent = self._parser_indent
self._parser_indent += 1 # new scope: must be higher #self._parser_indent += 1 # new scope: must be higher
self._new_indent = True #self._new_indent = True
if value != '@': if value != '@':
if self._first_stmt and not self._new_indent: if self._first_stmt and not self._new_indent:

View File

@@ -97,7 +97,9 @@ with_item: test ['as' expr]
with_var: 'as' expr with_var: 'as' expr
# NB compile.c makes sure that the default except clause is last # NB compile.c makes sure that the default except clause is last
except_clause: 'except' [test [(',' | 'as') test]] 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: # Backward compatibility cruft to support:
# [ x for x in lambda: True, lambda: False if x() ] # [ x for x in lambda: True, lambda: False if x() ]

View File

@@ -533,7 +533,6 @@ class Scope(Simple, DocstringMixin):
def imports(self): def imports(self):
return self._search_in_scope(Import) return self._search_in_scope(Import)
@Python3Method
def _search_in_scope(self, typ): def _search_in_scope(self, typ):
def scan(children): def scan(children):
elements = [] elements = []

View File

@@ -113,14 +113,15 @@ def test_if():
x = 3 x = 3
if x: if x:
def y(): def y():
x return x
x = 3 return y()
pass func()
''') ''')
# Two parsers needed, one for pass and one for the function. # Two parsers needed, one for pass and one for the function.
check_fp(src, 2) check_fp(src, 2)
assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int']
def test_incomplete_function(): def test_incomplete_function():