[Python-Dev] Requesting that a class be a new-style class
Michael Hudson
mwh at python.net
Sun Feb 20 10:38:29 CET 2005
Alex Martelli <aleax at aleax.it> writes:
> On 2005 Feb 20, at 04:35, Jack Diederich wrote:
>
>> I didn't dig into the C but does having 'type'
>> as metaclass guarantee the same behavior as inheriting 'object' or
>> does object
>> provide something type doesn't? *wince*
>
> I believe the former holds, since for example:
I was going to say that 'type(object) is type' is everything you need
to know, but you also need the bit of code in type_new that replaces
an empty bases tuple with (object,) -- but
class C:
__metaclass__ = Type
and
class C(object):
pass
produce identical classes.
> This is because types.ClassType turns somersaults to enable this: in
> this latter construct, Python's mechanisms determine ClassType as the
> metaclass (it's the metaclass of the first base class), but then
> ClassType in turn sniffs around for another metaclass to delegate to,
> among the supplied bases, and having found one washes its hands of the
> whole business;-).
It's also notable that type_new does exactly the same thing!
Cheers,
mwh
--
<etrepum> Jokes around here tend to get followed by implementations.
-- from Twisted.Quotes
More information about the Python-Dev
mailing list