Specifically, I would want MyClass.my_method
to be used for lookup of a value in the class dictionary, but MyClass.my_method()
to be a method that accepts arguments and performs a computation to update an attribute in MyClass
and then returns MyClass
with all its attributes (including the updated one).
I am thinking that this might be doable with Python's descriptors (maybe overriding __get__
or __call__
), but I can't figure out how this would look. I understand that the behavior might be confusing, but I am interested if it is possible (and if there are any other major caveats).
I have seen that you can do something similar for classes and functions by overriding __repr__
, but I can't find a similar way for a method within a class. My returned value will also not always be a string, which seems to prohibit the __repr__
-based approaches mentioned in these two questions: