This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients amaury.forgeotdarc, arigo, daniel.urban, fdrake, gvanrossum, isoschiz, kristjan.jonsson, ncoghlan, pconnell, pitrou
Date 2013-05-14.17:03:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368551005.49.0.596525207455.issue17950@psf.upfronthosting.co.za>
In-reply-to
Content
Kristjan, it seems you're in over your head. :-)

The mro() function is documented here:
http://docs.python.org/3/library/stdtypes.html?highlight=mro#class.mro
It exists to be called instead of using __mro__ directly; a metaclass can then override what it returns.  (Though I don't know if anyone has ever done this.)

The code you quote is in PyType_Ready() and skips bases[0] because bases[0] has already been used as the basic "template" for the C-level layout of the instances.  This particular loop adds additional slots to the layout and (most importantly) verifies that no bases are in conflict with the layout enforced by bases[0].  (This is required because we don't actually implement "virtual slots" at this level -- the C-level layout can only extend the first base class's layout.)

BTW, Armin is also right about the reason for using weak references in the __subclasses__ list.

As for replacing references with weak references, I would be much more concerned if you were proposing this for e.g. bound methods or instances, but that doesn't mean I'm completely unconcerned...

In addition to worrying about breaking (obscure) code that might depend on those references, I worry that it is trying to optimize for an unusual case (dynamically created classes in a world where you don't want to call gc.collect()) but slowing down the common case (access of the class from the descriptor every time a descriptor is used).

Specifically about your patch, I'm pretty sure there are some calls in there that don't expect a NULL pointer, as d_type is never NULL; but adding the weak reference makes it possible that your macro will return a NULL pointer.
History
Date User Action Args
2013-05-14 17:03:25gvanrossumsetrecipients: + gvanrossum, fdrake, arigo, amaury.forgeotdarc, ncoghlan, pitrou, kristjan.jonsson, daniel.urban, pconnell, isoschiz
2013-05-14 17:03:25gvanrossumsetmessageid: <1368551005.49.0.596525207455.issue17950@psf.upfronthosting.co.za>
2013-05-14 17:03:25gvanrossumlinkissue17950 messages
2013-05-14 17:03:25gvanrossumcreate