[Python-3000] __methods__ and __members__

Guido van Rossum guido at python.org
Sun Mar 11 01:21:09 CET 2007


On 3/9/07, Georg Brandl <g.brandl at gmx.net> wrote:
> Guido van Rossum schrieb:
> > I don't recall ripping them out, but it's worth trying to do that --
> > they really shouldn't be needed for modern extensionmodules (2.2+).
> >
> > On 3/7/07, Georg Brandl <g.brandl at gmx.net> wrote:
> >> While reviewing the patch for __dir__() (which I'll apply then, since it was
> >> generally agreed upon at least for Py3k), I came about this:
> >>
> >> /* Merge in __members__ and __methods__ (if any).
> >>     XXX Would like this to go away someday; for now, it's
> >>     XXX needed to get at im_self etc of method objects. */
> >>
> >> What is the status of __methods__ and __members__? Is this (and the docs)
> >> the only trace that's left of it?
>
> Okay, I looked into it.
> The old attribute semantics of offering a custom tp_getattr
> which dispatches to methods and members is mainly used in very old
> and platform-specific extension modules like RISCOS/*,
> Modules/{al,fl,sunaudiodev}module. If we decide to drop some of them,
> it would be nice to do it before working on them ;)

I'm sure we can drop al and fl. I expect we can drop sunaudiodev too,
and I seem to recall there's no-one to maintain the RISCOS code; but
for sunaudiodev and RISCOS it would be better to ask on python-dev.

> Then, we have cases like pyexpat.c, where attributes are dynamically
> read in getattr. This could also be done with tp_getset, but it may
> be quite a bit slower. But this is only one type, and it could get
> a custom __dir__ function.

I recommend doing the simplest thing that could possibly work. If it's
too slow someone will speed it up.

> There are also quite a few modules whose types have a getattr which
> only calls Py_FindMethod. This can easily be replaced with a tp_methods
> slot entry.

Yeah, they didn't get changed earlier because there was no incentive. :-)

> Another oddity is that Py_FindMethod checks if __doc__ is requested, and
> returns it. Is that still necessary?

I'm pretty sure the new code in typeobject.py handles that too --
otherwise how would __doc__ for modern types work?

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list