mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Fix an infer issue on literals after brackets, fixes #1657
This commit is contained in:
@@ -281,6 +281,11 @@ class Script:
|
||||
leaf = self._module_node.get_leaf_for_position(pos)
|
||||
if leaf is None or leaf.type == 'string':
|
||||
return []
|
||||
if leaf.end_pos == (line, column) and leaf.type == 'operator':
|
||||
next_ = leaf.get_next_leaf()
|
||||
if next_.start_pos == leaf.end_pos \
|
||||
and next_.type in ('number', 'string', 'keyword'):
|
||||
leaf = next_
|
||||
|
||||
context = self._get_module_context().create_context(leaf)
|
||||
|
||||
|
||||
@@ -370,3 +370,35 @@ def test_multi_goto(Script):
|
||||
y, = script.goto(line=4)
|
||||
assert x.line == 1
|
||||
assert y.line == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'code, column, expected', [
|
||||
('str() ', 3, 'str'),
|
||||
('str() ', 4, 'str'),
|
||||
('str() ', 5, 'str'),
|
||||
('str() ', 6, None),
|
||||
('str( ) ', 6, None),
|
||||
(' 1', 1, None),
|
||||
('str(1) ', 3, 'str'),
|
||||
('str(1) ', 4, 'int'),
|
||||
('str(1) ', 5, 'int'),
|
||||
('str(1) ', 6, 'str'),
|
||||
('str(1) ', 7, None),
|
||||
('str( 1) ', 4, 'str'),
|
||||
('str( 1) ', 5, 'int'),
|
||||
('str(+1) ', 4, 'str'),
|
||||
('str(+1) ', 5, 'int'),
|
||||
('str(1, 1.) ', 3, 'str'),
|
||||
('str(1, 1.) ', 4, 'int'),
|
||||
('str(1, 1.) ', 5, 'int'),
|
||||
('str(1, 1.) ', 6, None),
|
||||
('str(1, 1.) ', 7, 'float'),
|
||||
]
|
||||
)
|
||||
def test_infer_after_parentheses(Script, code, column, expected):
|
||||
completions = Script(code).infer(column=column)
|
||||
if expected is None:
|
||||
assert completions == []
|
||||
else:
|
||||
assert [c.name for c in completions] == [expected]
|
||||
|
||||
Reference in New Issue
Block a user