Tp_getattr vs. tp_methods

I’ve been building some extension classes in C/C++ and run into something I can’t figure out…

The class has custom getters and setters, these work fine and are setup using the .tp_getattr and .tp_setattr values in PyTypeObject

When I wanted to add some custom methods to the same class, I created a method table and linked it using .tp_methods. I’ve added methods in other extensions that I’ve written, but these don’t have custom getattr

When I call the new method, the interpreter calls my custom getattr function with the name of the method. Do I have to return something here to let the interpreter know that it should look in the method table? Or some way of returning a reference to the C implementation of the method?

Just to see, I returned a Python float of 42 from the getattr function and it didn’t like that at all (I knew this wouldn’t work, just trying to figure out what the interpreter wants):
TypeError: 'float' object is not callable


OK, doing a little experimentation and found that I can make it work by using tp_getset and tp_methods (not using tp_getattr & tp_setattr any more). I would like to figure out why this works though, to better understand the interpreter…