Skip to content

Variable redefinition in the same cell shows completions from previous value #15043

@Darshan808

Description

@Darshan808

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.

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions