-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Open
Description
Description:
When a variable is redefined in the same cell, tab-completions still show attributes of the previous type instead of the new one.
Reproduce
In [1]: a = 1
In [2]: a = []
a.<TAB> # shows completions like as_integer_ratio, real, etc.Expected behavior:
Completions should reflect the current type of the variable — in this case, list attributes such as append, extend, etc.
Cause:
In the _attr_matches function, if the object is already defined, we do not consider the lines above in the current cell.
ipython/IPython/core/completer.py
Lines 1271 to 1282 in 7bcf6fe
| obj = self._evaluate_expr(expr) | |
| if obj is not_found: | |
| if context: | |
| # try to evaluate on full buffer | |
| previous_lines = "\n".join( | |
| context.full_text.split("\n")[: context.cursor_line] | |
| ) | |
| if previous_lines: | |
| all_code_lines_before_cursor = ( | |
| self._extract_code(previous_lines) + "\n" + expr | |
| ) | |
| obj = self._evaluate_expr(all_code_lines_before_cursor) |
Metadata
Metadata
Assignees
Labels
No labels