I'm trying to override the dir method in a Python class. Inside I want to call the builtin dir method, but my attempts at calling it seem to be calling my method, rather than the default implementation.
The correct way to override the __dir__ method in python This question seemed relevant but doesn't answer the question since it seems their issue was with extending a numpy class, not with calling the default dir implementation for the class
Relevant code
def __dir__(self):
return builtins.dir(self) + self.fields()
In other words I want everything that would normally be listed plus some other things, but the builtins.dir() call just calls this function recursively.
I'm testing this in Python 3.6