From c446bcf885b9efe7715768b93f2c3d9000d57582 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 6 Dec 2018 00:59:56 +0100 Subject: [PATCH] Fix Python 3.5 issues --- jedi/evaluate/__init__.py | 6 ++++-- jedi/plugins/typeshed.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 9a6428b9..2be17f30 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -419,14 +419,16 @@ class Evaluator(object): scope_node = parent_scope(node) return from_scope_node(scope_node, is_nested=True, node_is_object=node_is_object) - def parse_and_get_code(self, code=None, path=None, encoding='utf-8', **kwargs): + def parse_and_get_code(self, code=None, path=None, encoding='utf-8', + use_latest_grammar=False, **kwargs): if self.allow_different_encoding: if code is None: with open(path, 'rb') as f: code = f.read() code = python_bytes_to_unicode(code, encoding=encoding, errors='replace') - return self.grammar.parse(code=code, path=path, **kwargs), code + grammar = self.latest_grammar if use_latest_grammar else self.grammar + return grammar.parse(code=code, path=path, **kwargs), code def parse(self, *args, **kwargs): return self.parse_and_get_code(*args, **kwargs)[0] diff --git a/jedi/plugins/typeshed.py b/jedi/plugins/typeshed.py index e572824c..1bb6eeb5 100644 --- a/jedi/plugins/typeshed.py +++ b/jedi/plugins/typeshed.py @@ -75,7 +75,7 @@ def _get_typeshed_directories(version_info): @evaluator_function_cache() def _load_stub(evaluator, path): - return evaluator.parse(path=path, cache=True) + return evaluator.parse(path=path, cache=True, use_latest_grammar=True) def _merge_modules(context_set, stub_context): @@ -162,7 +162,9 @@ class TypeshedPlugin(BasePlugin): context_set, evaluator, stub_module_node, path=path, string_names=import_names, - code_lines=get_cached_code_lines(evaluator.grammar, path), + # The code was loaded with latest_grammar, so use + # that. + code_lines=get_cached_code_lines(evaluator.latest_grammar, path), ) modules = _merge_modules(context_set, stub_module_context) return ContextSet(modules)