[Python-3000] Help replacing Py_FindMethod

Amaury Forgeot d'Arc amauryfa at gmail.com
Tue Jul 29 17:19:32 CEST 2008

Jesus Cea wrote:
> Amaury Forgeot d'Arc wrote:
> |> My doubt now is how do write a *clever* "getattr" routine without
> |> "Py_FindMethod".
> |
> | Well, I'd write a "tp_getattro" member function,
> | which would do its "clever" things before it falls back to
> | PyObject_GenericGetAttr to get the usual behaviour.
> Now I'm confused about difference between "tp_getattro" and
> "tp_getattr", and when to use them.

They are identical, except that tp_getattr takes a char*, when
tp_getattro wants a PyObject*.
(see the code in Object/object.c::PyObject_GetAttr())

> I guess that "tp_methods" and "tp_members" are faster, but only usable
> when the data is "static" and available, while "tp_getattr" and friends
> are used when you need to execute some code in the lookup.

Yes. Fortunately, it's not often the case.

> But I read
> somewhere that "tp_getattr" was deprecated :-? ...

Deprecated in favor of tp_getattro I presume.

Amaury Forgeot d'Arc

More information about the Python-3000 mailing list