jedi
jedi copied to clipboard
Autocomplete for chained methods
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:
- I have found no previous issue here apart from this one and this one on the ipython kernel.
Versions
- Python 3.11.9
- Jedi 0.19.1
- ipykernel 6.29.5
- ipython 8.27.0
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.
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?
I agree. Sorry for not reading the issue description properly.
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.
I'm reopening, because AFAIK Self is not supported. @PeterJCLaw It might be that I'm wrong here, not 100% sure.
I believe Self is not supported yet.