What is the status of the __subclasses__ method?

Michael Hudson mwh at python.net
Fri Feb 27 16:11:12 CET 2004

Ruud de Jong <ruud.de.jong at consunet.nl> writes:

> The question I have is: how safe / future proof / portable is the
> use of the __subclasses__ method that exists for new-style classes?

Hmm.  I think it's unlikely to go away.

> When I searched python.org for "__subclasses__" I found
> some more information. The __subclasses__ method appears
> to exist to allow modifications of the superclass to be
> percolated down to its children, mainly for speed reasons,
> if I understand Tim Peter's explanation correctly
> (http://mail.python.org/pipermail/python-list/2003-August/176360.html). 


> I also found several warnings that the __subclasses__ method only
> returns classes that have been accessed previously (which would
> defeat my purpose)

Hum, you're being overly paranoid here.  Python defined types are
PyType_Ready-ed as soon as they are created.

> So again, my question. Is it safe to use the __subclasses__
> method for the purpose I described above? 

Well, I can't see into the future, but I'd feel secure using it.

I'm not sure what you describe is a very tasteful use of it though...

> Or would it be safer to revert to my home-grown metaclass solution?

You might want to keep it around, I guess...


  I would hereby duly point you at the website for the current pedal
  powered submarine world underwater speed record, except I've lost
  the URL.                                         -- Callas, cam.misc

More information about the Python-list mailing list