Anonymous class question

Alex Martelli aleax at aleax.it
Fri Aug 8 11:28:21 EDT 2003


Dan Williams wrote:
   ...
>>>>self.file = type("", (object,), {'close':lambda slf: None})()
>>>
>> Does that (object,) do something I'm missing?
>> 
>>  >>> o1 = type('',(object,),{})()
>>  >>> o2 = type('',(),{})()
>>  >>> type(o1).__bases__
>>  (<type 'object'>,)
>>  >>> type(o2).__bases__
>>  (<type 'object'>,)
>> 
>> Regards,
>> Bengt Richter
> 
> I thought it made it a new-style class. I could be wrong about that,
> though. . .

Class whose metaclass is type (and it surely will be, if you
instantiate type directly by calling it as you did) ARE "new
style" by definition.  Don't be confused with the class
statement: _then_ you may need to explicitly specify object
as a base class [or otherwise set the __metaclass__] in order
to have a class be new-style rather than the default 'classic'.
But when you explicitly call type, specifiying object as the
only base is not necessary (although, it _is_ innocuous).


Alex





More information about the Python-list mailing list