Refactor to avoid having unicode decode errors by default

This commit is contained in:
Dave Halter
2018-01-19 19:23:11 +01:00
parent c1394a82b5
commit 16b463a646
5 changed files with 36 additions and 34 deletions
+14
View File
@@ -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]