Fix Python 3.5 issues

This commit is contained in:
Dave Halter
2018-12-06 00:59:56 +01:00
parent d9e711ab11
commit c446bcf885
2 changed files with 8 additions and 4 deletions

View File

@@ -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]

View File

@@ -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)