You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a list of instances of one class (Cat) stored in a container class (Cats) as an attribute. I created a __getitem__ method in the container class that retrieves items from the list by index. When I use that method to get an item in the list, the attribute autocomplete options do not appear for that Cat object. The attributes do appear in tab-complete when I call the list by index directly.
In [1]: class Cats:
...: def __init__(self, cat_list):
...: self.cat_list = cat_list
...:
...: def __getitem__(self, key):
...: return self.cat_list[key]
...:
...: class Cat:
...: def __init__(self, name, color):
...: self.name = name
...: self.color = color
In [2]: cat1 = Cat('Muffy', 'brown')
...: cat2 = Cat('Fluffy', 'white')
...: cat3 = Cat('Tuffy', 'tuxedo')
...: all_cats = [cat1, cat2, cat3]
...: cats = Cats(cat_list=all_cats)
In [3]: cats[0] == cats.cat_list[0]
Out[3]: True
In [4]: cats[0].name
Out[4]: 'Muffy'
In [5]: cats.cat_list[0].<tab> # name, color at top of tab-complete list
In [6]: cats[0].<tab> # name and color do not appear
The text was updated successfully, but these errors were encountered:
I'll look into it, but that might be something we do on purpose for __getitem__ as it may have side effects.
A long time ago we had a bug report from people using __getitem__ to access an electronic device values. The problem with electronic devices being that most of the time when you read the value they get erased to leave place for the next one. That lead to the problematic.
>>> device['x_voltage'].<tab>
Trying to read the content of x_voltage and thus erasing the value.
You can try to turn on "greedy" completion.
--Completer.greedy=<Bool>
Activate greedy completion
PENDING DEPRECATION. this is now mostly taken care of with Jedi.
This will enable completion on elements of lists, results of function calls, etc.,
but can be unsafe because the code is actually evaluated on TAB.
Default: False
Strange thing is that even with greedy completion it does not show (which I would expect), so there might be something else happening.
I have a list of instances of one class (
Cat
) stored in a container class (Cats
) as an attribute. I created a__getitem__
method in the container class that retrieves items from the list by index. When I use that method to get an item in the list, the attribute autocomplete options do not appear for thatCat
object. The attributes do appear in tab-complete when I call the list by index directly.The text was updated successfully, but these errors were encountered: