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

Autocomplete for chained methods #2023

Open
niklassemmler opened this issue Sep 10, 2024 · 6 comments
Open

Autocomplete for chained methods #2023

niklassemmler opened this issue Sep 10, 2024 · 6 comments
Labels

Comments

@niklassemmler
Copy link

Just today I figured out that Jedi has been powering my ipython/jupyter/vim experience all along. Thank you :)

To the question. Is it possible to autocomplete chained methods, e.g., for a builder pattern?

On Jedi 0.19.1 I can not get the autocomplete for add_y to work in either ipython or jupyter for the following example:

from typing import Self

class Builder:
    def __init__(self):
        self.x = 0
        self.y = 0
        
    def add_x(self: Self, x: int) -> Self:
        self.x = x
        return self

    def add_y(self: Self, y: int) -> Self:
        self.y = y
        return self

b = Builder()
b.add_x(2).add_y(5)
#^ this autcompletes
#         ^ this doesn't

I have experimented with -> "Builder": as well with the same result.

Other issues:

Versions

  • Python 3.11.9
  • Jedi 0.19.1
  • ipykernel 6.29.5
  • ipython 8.27.0
@davidhalter
Copy link
Owner

Self is probably not supported. I'm pretty sure you could work around that by either removing the annotation or returning -> Builder, but that also sounds like a bad idea.

@PeterJCLaw
Copy link
Collaborator

Removing the Self annotations (both on self and the return) and either adding -> Builder or leaving that empty feel like they should work here, both in ipython and in editors. If that's not working then perhaps something else is going on?

@davidhalter davidhalter added bug and removed feature labels Sep 11, 2024
@davidhalter
Copy link
Owner

I agree. Sorry for not reading the issue description properly.

@niklassemmler
Copy link
Author

I tried again with "Builder" and autocomplete did work. Just not in the more complicated example I have. So I must have mixed sth up when evaluating this earlier. My apologies. Still good to know that Self is not supported.

@davidhalter
Copy link
Owner

I'm reopening, because AFAIK Self is not supported. @PeterJCLaw It might be that I'm wrong here, not 100% sure.

@PeterJCLaw
Copy link
Collaborator

I believe Self is not supported yet.

@davidhalter davidhalter reopened this Sep 11, 2024
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

3 participants