mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
fix local imports in repl completion
This commit is contained in:
@@ -61,11 +61,17 @@ def setup_readline(namespace_module=__main__):
|
||||
library module.
|
||||
"""
|
||||
if state == 0:
|
||||
interpreter = Interpreter(text, [namespace_module.__dict__])
|
||||
import os, sys
|
||||
sys.path.insert(0, os.getcwd())
|
||||
# Calling python doesn't have a path, so add to sys.path.
|
||||
try:
|
||||
interpreter = Interpreter(text, [namespace_module.__dict__])
|
||||
|
||||
path, dot, like = interpreter._get_completion_parts()
|
||||
before = text[:len(text) - len(like)]
|
||||
completions = interpreter.completions()
|
||||
path, dot, like = interpreter._get_completion_parts()
|
||||
before = text[:len(text) - len(like)]
|
||||
completions = interpreter.completions()
|
||||
finally:
|
||||
sys.path.pop(0)
|
||||
|
||||
self.matches = [before + c.name_with_symbols for c in completions]
|
||||
try:
|
||||
|
||||
@@ -71,6 +71,10 @@ class TestSetupReadline(TestCase):
|
||||
# items as well as items that are not only available on linux.
|
||||
assert len(set(self.completions(s)).symmetric_difference(goal)) < 20
|
||||
|
||||
def test_local_import(self):
|
||||
s = 'import test_utils'
|
||||
assert self.completions(s) == [s]
|
||||
|
||||
def test_preexisting_values(self):
|
||||
self.namespace.a = range(10)
|
||||
assert set(self.completions('a.')) == set(['a.' + n for n in dir(range(1))])
|
||||
|
||||
Reference in New Issue
Block a user