[Python-Dev] Requesting that a class be a new-style class (original) (raw)
Michael Hudson mwh at python.net
Sun Feb 20 10:38:29 CET 2005
- Previous message: [Python-Dev] Requesting that a class be a new-style class
- Next message: [Python-Dev] Requesting that a class be a new-style class
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
-- Jokes around here tend to get followed by implementations. -- from Twisted.Quotes
- Previous message: [Python-Dev] Requesting that a class be a new-style class
- Next message: [Python-Dev] Requesting that a class be a new-style class
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]