Python update self.__dict__ in __getattribute__ immediately

Viewed 46

I am doing nested object and I am able to perform dot tab auto-complete to navigate to the next level of the object. I understand that __getattribute__ is called and if the name is not found in the self.__dict__ then __getattr__ will be called. Correct me if I am wrong.

Is it possible to update self.__dict__ in overwriting __getattribute__, and when I perform the dot tab it shows the updated option to auto-complete?

My current implementation:

def __getattribute__(self, name):
    if condition:
        object.__setattr__(self, '__dict__', dictionary to be added)
    else:
        return object.__getattribute__(self, name)

I am able to add the object but it's not available in the first tab, it is only available in the second tab.

What I am trying to achieve is for the tab to show the updated object/variable on the first tab. I am thinking about return something instead of just __setattr__, But I have no idea what to return. Any pointer will be welcome.

1 Answers

Overwriting the __dir__, as it is called in the pyreadline.

Related