mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Fix issues with a recent refactoring
This commit is contained in:
@@ -360,7 +360,7 @@ 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, path, **kwargs):
|
def parse_and_get_code(self, code=None, path=None, **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:
|
||||||
|
|||||||
@@ -379,7 +379,7 @@ def get_global_filters(evaluator, context, until_position, origin_scope):
|
|||||||
... def func():
|
... def func():
|
||||||
... y = None
|
... y = None
|
||||||
... '''))
|
... '''))
|
||||||
>>> module_node = script._get_module_node()
|
>>> module_node = script._module_node
|
||||||
>>> scope = next(module_node.iter_funcdefs())
|
>>> scope = next(module_node.iter_funcdefs())
|
||||||
>>> scope
|
>>> scope
|
||||||
<Function: func@3-5>
|
<Function: func@3-5>
|
||||||
|
|||||||
@@ -369,9 +369,20 @@ class Importer(object):
|
|||||||
else:
|
else:
|
||||||
module_path = get_init_path(module_path)
|
module_path = get_init_path(module_path)
|
||||||
elif module_file:
|
elif module_file:
|
||||||
|
if module_path.endswith(('.zip', '.egg')):
|
||||||
|
# Unfortunately we are reading unicode here already, not byes.
|
||||||
|
# It seems however hard to get bytes, because the zip importer
|
||||||
|
# logic just unpacks the zip file and returns a file descriptor
|
||||||
|
# that we cannot as easily access. Therefore we just read it as
|
||||||
|
# a string.
|
||||||
|
code = module_file.read()
|
||||||
|
else:
|
||||||
|
# Read the code with a binary file, because the binary file
|
||||||
|
# might not be proper unicode. This is handled by the parser
|
||||||
|
# wrapper.
|
||||||
|
with open(module_path, 'rb') as f:
|
||||||
|
code = f.read()
|
||||||
module_file.close()
|
module_file.close()
|
||||||
with open(module_path, 'rb') as f:
|
|
||||||
code = f.read()
|
|
||||||
|
|
||||||
if isinstance(module_path, ImplicitNSInfo):
|
if isinstance(module_path, ImplicitNSInfo):
|
||||||
from jedi.evaluate.context.namespace import ImplicitNamespaceContext
|
from jedi.evaluate.context.namespace import ImplicitNamespaceContext
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ def setup_readline(namespace_module=__main__):
|
|||||||
lines = split_lines(text)
|
lines = split_lines(text)
|
||||||
position = (len(lines), len(lines[-1]))
|
position = (len(lines), len(lines[-1]))
|
||||||
name = get_on_completion_name(
|
name = get_on_completion_name(
|
||||||
interpreter._get_module_node(),
|
interpreter._module_node,
|
||||||
lines,
|
lines,
|
||||||
position
|
position
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ def test_complete_at_zero():
|
|||||||
def test_wrong_encoding(cwd_tmpdir):
|
def test_wrong_encoding(cwd_tmpdir):
|
||||||
x = cwd_tmpdir.join('x.py')
|
x = cwd_tmpdir.join('x.py')
|
||||||
# Use both latin-1 and utf-8 (a really broken file).
|
# Use both latin-1 and utf-8 (a really broken file).
|
||||||
x.write_binary(u'foobar = 1\nä'.encode('latin-1') + 'ä'.encode())
|
x.write_binary(u'foobar = 1\nä'.encode('latin-1') + u'ä'.encode('utf-8'))
|
||||||
|
|
||||||
c, = Script('import x; x.foo', sys_path=['.']).completions()
|
c, = Script('import x; x.foo', sys_path=['.']).completions()
|
||||||
assert c.name == 'foobar'
|
assert c.name == 'foobar'
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from jedi import Script
|
|||||||
def test_paths_from_assignment():
|
def test_paths_from_assignment():
|
||||||
def paths(src):
|
def paths(src):
|
||||||
script = Script(src, path='/foo/bar.py')
|
script = Script(src, path='/foo/bar.py')
|
||||||
expr_stmt = script._get_module_node().children[0]
|
expr_stmt = script._module_node.children[0]
|
||||||
return set(sys_path._paths_from_assignment(script._get_module(), expr_stmt))
|
return set(sys_path._paths_from_assignment(script._get_module(), expr_stmt))
|
||||||
|
|
||||||
assert paths('sys.path[0:0] = ["a"]') == {'/foo/a'}
|
assert paths('sys.path[0:0] = ["a"]') == {'/foo/a'}
|
||||||
|
|||||||
Reference in New Issue
Block a user