Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of type annotation breaks tab completion in jedi>=0.19.0 #1970

Open
daveah opened this issue Nov 14, 2023 · 0 comments
Open

Addition of type annotation breaks tab completion in jedi>=0.19.0 #1970

daveah opened this issue Nov 14, 2023 · 0 comments
Labels

Comments

@daveah
Copy link

daveah commented Nov 14, 2023

Start with this code in ipython with jedi enabled for tab completion:

from typing import Iterable, Any

class Bar:
    def __dir__(self) -> Iterable[str]:
        return ("a", "b", "c")
    
    def __getattr__(self, key: str) -> Any:
        if key not in ("a", "b", "c"):
            raise AttributeError
        return self[key]
    
    def __getitem__(self, key: str) -> "Bar":
        return Bar()
    

class Foo:
    _b: Bar | None

    def __init__(self) -> None:
        self._b = None

    @property
    def b(self):
        if not self._b:
            self._b = Bar()
        return self._b

f = Foo()
f.b.   <hit tab>

We get what we expect with a menu of a, b, c in jedi 0.18.1 or 0.19.0 and later

Now add a type annotation to the @property in Foo:

from typing import Iterable, Any

class Bar:
    def __dir__(self) -> Iterable[str]:
        return ("a", "b", "c")
    
    def __getattr__(self, key: str) -> Any:
        if key not in ("a", "b", "c"):
            raise AttributeError
        return self[key]
    
    def __getitem__(self, key: str) -> "Bar":
        return Bar()
    

class Foo:
    _b: Bar | None

    def __init__(self) -> None:
        self._b = None

    @property
    def b(self) -> Bar:
        if not self._b:
            self._b = Bar()
        return self._b

f = Foo()
f.b.   <hit tab>

This now works in 0.18.2 but fails in 0.19.0 and above.

Possibly as a result of one of these commits:
972123c
ff3a7f3
886279f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants