mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Fix Python 3.5 issues
This commit is contained in:
@@ -419,14 +419,16 @@ class Evaluator(object):
|
|||||||
scope_node = parent_scope(node)
|
scope_node = parent_scope(node)
|
||||||
return from_scope_node(scope_node, is_nested=True, node_is_object=node_is_object)
|
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 self.allow_different_encoding:
|
||||||
if code is None:
|
if code is None:
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
code = f.read()
|
code = f.read()
|
||||||
code = python_bytes_to_unicode(code, encoding=encoding, errors='replace')
|
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):
|
def parse(self, *args, **kwargs):
|
||||||
return self.parse_and_get_code(*args, **kwargs)[0]
|
return self.parse_and_get_code(*args, **kwargs)[0]
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ def _get_typeshed_directories(version_info):
|
|||||||
|
|
||||||
@evaluator_function_cache()
|
@evaluator_function_cache()
|
||||||
def _load_stub(evaluator, path):
|
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):
|
def _merge_modules(context_set, stub_context):
|
||||||
@@ -162,7 +162,9 @@ class TypeshedPlugin(BasePlugin):
|
|||||||
context_set, evaluator, stub_module_node,
|
context_set, evaluator, stub_module_node,
|
||||||
path=path,
|
path=path,
|
||||||
string_names=import_names,
|
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)
|
modules = _merge_modules(context_set, stub_module_context)
|
||||||
return ContextSet(modules)
|
return ContextSet(modules)
|
||||||
|
|||||||
Reference in New Issue
Block a user