diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 40102047..01ed0a34 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -570,6 +570,13 @@ class Interpreter(Script): super(Interpreter, self).__init__(source, **kwds) self.namespaces = namespaces + # Don't use the fast parser, because it does crazy stuff that we don't + # need in our very simple and small code here (that is always + # changing). + self._parser = UserContextParser(self._grammar, self.source, + self._orig_path, self._pos, + self._user_context, + use_fast_parser=False) interpreter.add_namespaces_to_parser(self._evaluator, namespaces, self._parser.module()) diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index fdb24aec..b68fa071 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -18,7 +18,7 @@ The easiest way to play with this module is to use :class:`parsing.Parser`. >>> parser = Parser(load_grammar(), u('import os'), 'example.py') >>> submodule = parser.module >>> submodule - + Any subclasses of :class:`Scope`, including :class:`SubModule` has an attribute :attr:`imports `: diff --git a/jedi/parser/user_context.py b/jedi/parser/user_context.py index 8e4f5da1..e1ff1f5b 100644 --- a/jedi/parser/user_context.py +++ b/jedi/parser/user_context.py @@ -4,7 +4,7 @@ import keyword from jedi import cache from jedi import common -from jedi.parser import tokenize +from jedi.parser import tokenize, Parser from jedi._compatibility import u from jedi.parser.fast import FastParser from jedi.parser import tree as pr @@ -235,19 +235,24 @@ class UserContext(object): class UserContextParser(object): - def __init__(self, grammar, source, path, position, user_context): + def __init__(self, grammar, source, path, position, user_context, + use_fast_parser=True): self._grammar = grammar self._source = source self._path = path and os.path.abspath(path) self._position = position self._user_context = user_context + self._use_fast_parser = use_fast_parser @cache.underscore_memoization def _parser(self): cache.invalidate_star_import_cache(self._path) - parser = FastParser(self._grammar, self._source, self._path) - # Don't pickle that module, because the main module is changing quickly - cache.save_parser(self._path, None, parser, pickling=False) + if self._use_fast_parser: + parser = FastParser(self._grammar, self._source, self._path) + # Don't pickle that module, because the main module is changing quickly + cache.save_parser(self._path, None, parser, pickling=False) + else: + parser = Parser(self._grammar, self._source, self._path) return parser @cache.underscore_memoization