jedi icon indicating copy to clipboard operation
jedi copied to clipboard

Autocomplete for chained methods

Open niklassemmler opened this issue 1 year ago • 6 comments

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

niklassemmler avatar Sep 10 '24 08:09 niklassemmler

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.

davidhalter avatar Sep 10 '24 09:09 davidhalter

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?

PeterJCLaw avatar Sep 10 '24 22:09 PeterJCLaw

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

davidhalter avatar Sep 11 '24 08:09 davidhalter

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.

niklassemmler avatar Sep 11 '24 11:09 niklassemmler

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

davidhalter avatar Sep 11 '24 20:09 davidhalter

I believe Self is not supported yet.

PeterJCLaw avatar Sep 11 '24 20:09 PeterJCLaw