Skip to content

Commit cd483f2

Browse files
authored
Fix error on tab completions (ipython#15076)
### Fixes ipython#15075 ### Description Added a logic to check whether the node we have is `ast.Expr` before trying to access its `value`.
2 parents ee7ad52 + a2fe4da commit cd483f2

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

IPython/core/completer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,8 @@ def _trim_expr(self, code: str) -> str:
13521352
assert res is not None
13531353
if len(res.body) != 1:
13541354
continue
1355+
if not isinstance(res.body[0], ast.Expr):
1356+
continue
13551357
expr = res.body[0].value
13561358
if isinstance(expr, ast.Tuple) and not code[-1] == ")":
13571359
# we skip implicit tuple, like when trimming `fun(a,b`<completion>

tests/test_completer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,7 @@ def test_misc_no_jedi_completions(setup, code, expected, not_expected):
26882688
("x = {1, y", "y"),
26892689
("x = [1, y", "y"),
26902690
("x = fun(1, y", "y"),
2691+
(" assert a", "a"),
26912692
],
26922693
)
26932694
def test_trim_expr(code, expected):

0 commit comments

Comments
 (0)