forked from VimPlug/jedi
Refactor to avoid having unicode decode errors by default
This commit is contained in:
@@ -66,6 +66,7 @@ import sys
|
||||
|
||||
from parso.python import tree
|
||||
import parso
|
||||
from parso import python_bytes_to_unicode
|
||||
|
||||
from jedi import debug
|
||||
from jedi import parser_utils
|
||||
@@ -103,6 +104,7 @@ class Evaluator(object):
|
||||
project.add_evaluator(self)
|
||||
|
||||
self.reset_recursion_limitations()
|
||||
self.allow_different_encoding = False
|
||||
|
||||
# Constants
|
||||
self.BUILTINS = compiled.get_special_object(self, 'BUILTINS')
|
||||
@@ -357,3 +359,15 @@ class Evaluator(object):
|
||||
node = node.parent
|
||||
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, path, **kwargs):
|
||||
if self.allow_different_encoding:
|
||||
if code is None:
|
||||
with open('rb') as f:
|
||||
code = f.read()
|
||||
code = python_bytes_to_unicode(code, errors='replace')
|
||||
|
||||
return self.grammar.parse(code=code, path=path, **kwargs), code
|
||||
|
||||
def parse(self, *args, **kwargs):
|
||||
return self.parse_and_get_code(*args, **kwargs)[0]
|
||||
|
||||
Reference in New Issue
Block a user