forked from VimPlug/jedi
The encoding parameter should be used again (includes test), fixes #1167
This commit is contained in:
@@ -112,9 +112,10 @@ class Script(object):
|
|||||||
self._module_node, source = self._evaluator.parse_and_get_code(
|
self._module_node, source = self._evaluator.parse_and_get_code(
|
||||||
code=source,
|
code=source,
|
||||||
path=self.path,
|
path=self.path,
|
||||||
|
encoding=encoding,
|
||||||
cache=False, # No disk cache, because the current script often changes.
|
cache=False, # No disk cache, because the current script often changes.
|
||||||
diff_cache=settings.fast_parser,
|
diff_cache=settings.fast_parser,
|
||||||
cache_path=settings.cache_directory
|
cache_path=settings.cache_directory,
|
||||||
)
|
)
|
||||||
debug.speed('parsed')
|
debug.speed('parsed')
|
||||||
self._code_lines = parso.split_lines(source, keepends=True)
|
self._code_lines = parso.split_lines(source, keepends=True)
|
||||||
|
|||||||
@@ -373,12 +373,12 @@ 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, **kwargs):
|
def parse_and_get_code(self, code=None, path=None, encoding='utf-8', **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, errors='replace')
|
code = python_bytes_to_unicode(code, encoding=encoding, errors='replace')
|
||||||
|
|
||||||
return self.grammar.parse(code=code, path=path, **kwargs), code
|
return self.grammar.parse(code=code, path=path, **kwargs), code
|
||||||
|
|
||||||
|
|||||||
@@ -72,3 +72,9 @@ def test_wrong_encoding(Script, tmpdir):
|
|||||||
|
|
||||||
c, = Script('import x; x.foo', sys_path=[tmpdir.strpath]).completions()
|
c, = Script('import x; x.foo', sys_path=[tmpdir.strpath]).completions()
|
||||||
assert c.name == 'foobar'
|
assert c.name == 'foobar'
|
||||||
|
|
||||||
|
|
||||||
|
def test_encoding_parameter(Script):
|
||||||
|
name = u('hö')
|
||||||
|
s = Script(name.encode('latin-1'), encoding='latin-1')
|
||||||
|
assert s._module_node.get_code() == name
|
||||||
|
|||||||
Reference in New Issue
Block a user