[Python-Dev] Re: Hot-To Guide for Descriptors - Nits! :-)

François Pinard pinard at iro.umontreal.ca
Thu Jan 22 10:06:12 EST 2004


[Christian Tanzer]

> François Pinard <pinard at iro.umontreal.ca> wrote:

> > [...] found by scanning the base classes of the current class, and
> > `object' always when there is no base class for a "new-style" class.

> As always, a little experiment at the interactive prompt is
> instructive: [...]

Indeed.  One more tiny experiment is also enlightening:


Python 2.3.3 (#1, Jan 21 2004, 22:36:17) 
>>> __metaclass__ = type
>>> class A: pass
... 
>>> A.__bases__
(<type 'object'>,)
>>> A.__mro__
(<class '__main__.A'>, <type 'object'>)
>>> 


(I merely added __mro__ to your example) which seems to confirm that
`object' is always implied if the metaclass is `type', exactly as if it
was explicitly listed as a base.

Unless the above experiment just reveals some unspecified behaviour,
which just happens to not correctly be in-lined with Guido's intents?
That is possible, yet it seems unlikely.  Only Guido really knows! :-)

Maybe we should not overly state that one ought to explicitly sub-class
a class from `object' to get a new style class, nor suggest that not
doing so might yield broken classes with unpredictable behaviour.

Of course, we have been educated to read "class A(object):" as the
standard way to flag `A' as being new-style, but if I could avoid adding
such "(object)" everywhere in the code, and merely declare __metaclass__
once per module, it looks much neater to me.  Taste varies :-). More it
goes, more it looks like my fears were not really sounded.

Thanks to all those who participated in clarifying this little issue.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard



More information about the Python-Dev mailing list