mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Correct issues with slices and some more subtle bugs.
This commit is contained in:
@@ -75,12 +75,12 @@ class LazyName(helpers.FakeName):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
# cut the `c` from `.pyc`
|
||||||
path = re.sub('c$', '', path)
|
path = re.sub('c$', '', path)
|
||||||
if path.endswith('.py'):
|
if path.endswith('.py'):
|
||||||
# cut the `c` from `.pyc`
|
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
source = source_to_unicode(f.read())
|
source = source_to_unicode(f.read())
|
||||||
mod = FastParser(load_grammar(), source, path[:-1]).module
|
mod = FastParser(load_grammar(), source, path).module
|
||||||
if parser_path:
|
if parser_path:
|
||||||
assert len(parser_path) == 1
|
assert len(parser_path) == 1
|
||||||
found = self._evaluator.find_types(mod, parser_path[0], search_global=True)
|
found = self._evaluator.find_types(mod, parser_path[0], search_global=True)
|
||||||
@@ -88,7 +88,7 @@ class LazyName(helpers.FakeName):
|
|||||||
found = [self._evaluator.wrap(mod)]
|
found = [self._evaluator.wrap(mod)]
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
debug.warning('Possibly an interpreter lookup for Python code failed %s',
|
debug.warning('Interpreter lookup failed in global scope for %s',
|
||||||
parser_path)
|
parser_path)
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None):
|
|||||||
# Check name
|
# Check name
|
||||||
key, values = args[1]
|
key, values = args[1]
|
||||||
assert len(values) == 1
|
assert len(values) == 1
|
||||||
names = evaluator.eval_element(values[0])
|
names = list(evaluator.eval_element(values[0]))
|
||||||
assert len(names) == 1 and isinstance(names[0], CompiledObject)
|
assert len(names) == 1 and isinstance(names[0], CompiledObject)
|
||||||
assert names[0].obj == str(payload[1])
|
assert names[0].obj == str(payload[1])
|
||||||
|
|
||||||
|
|||||||
@@ -634,11 +634,11 @@ class Slice(object):
|
|||||||
|
|
||||||
result = self._evaluator.eval_element(element)
|
result = self._evaluator.eval_element(element)
|
||||||
if len(result) != 1:
|
if len(result) != 1:
|
||||||
# We want slices to be clear defined with just one type.
|
# For simplicity, we want slices to be clear defined with just
|
||||||
# Otherwise we will return an empty slice object.
|
# one type. Otherwise we will return an empty slice object.
|
||||||
raise IndexError
|
raise IndexError
|
||||||
try:
|
try:
|
||||||
return result[0].obj
|
return list(result)[0].obj
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ def collections_namedtuple(evaluator, obj, arguments):
|
|||||||
|
|
||||||
# Parse source
|
# Parse source
|
||||||
generated_class = Parser(evaluator.grammar, unicode(source)).module.subscopes[0]
|
generated_class = Parser(evaluator.grammar, unicode(source)).module.subscopes[0]
|
||||||
return set(er.Class(evaluator, generated_class))
|
return set([er.Class(evaluator, generated_class)])
|
||||||
|
|
||||||
|
|
||||||
@argument_clinic('first, /')
|
@argument_clinic('first, /')
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ class TestGotoAssignments(TestCase):
|
|||||||
n = nms[1].goto_assignments()[0]
|
n = nms[1].goto_assignments()[0]
|
||||||
# This is very special, normally the name doesn't chance, but since
|
# This is very special, normally the name doesn't chance, but since
|
||||||
# os.path is a sys.modules hack, it does.
|
# os.path is a sys.modules hack, it does.
|
||||||
assert n.name in ('ntpath', 'posixpath')
|
assert n.name in ('ntpath', 'posixpath', 'os2emxpath')
|
||||||
assert n.type == 'module'
|
assert n.type == 'module'
|
||||||
|
|
||||||
def test_import_alias(self):
|
def test_import_alias(self):
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ def test_paths_from_assignment():
|
|||||||
def paths(src):
|
def paths(src):
|
||||||
grammar = load_grammar()
|
grammar = load_grammar()
|
||||||
stmt = Parser(grammar, unicode(src)).module.statements[0]
|
stmt = Parser(grammar, unicode(src)).module.statements[0]
|
||||||
return list(sys_path._paths_from_assignment(Evaluator(grammar), stmt))
|
return set(sys_path._paths_from_assignment(Evaluator(grammar), stmt))
|
||||||
|
|
||||||
assert paths('sys.path[0:0] = ["a"]') == ['a']
|
assert paths('sys.path[0:0] = ["a"]') == set(['a'])
|
||||||
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == ['b', 'c']
|
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == set(['b', 'c'])
|
||||||
assert paths('sys.path = a = ["a"]') == ['a']
|
assert paths('sys.path = a = ["a"]') == set(['a'])
|
||||||
|
|
||||||
# Fail for complicated examples.
|
# Fail for complicated examples.
|
||||||
assert paths('sys.path, other = ["a"], 2') == []
|
assert paths('sys.path, other = ["a"], 2') == set()
|
||||||
|
|
||||||
|
|
||||||
def test_get_sys_path(monkeypatch):
|
def test_get_sys_path(monkeypatch):
|
||||||
|
|||||||
Reference in New Issue
Block a user