type() new style class instance says "class", not "ObjectType"

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Thu Apr 11 13:50:54 EDT 2002


On 11 Apr 2002 05:28:34 +0300, Erno Kuusela <erno-news at erno.iki.fi> wrote:
>In article <slrnab9o7v.i8b.huaiyu at gauss.almadan.ibm.com>,
>huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) writes:
>
>| On Wed, 10 Apr 2002 18:38:47 -0400, Brad Clements
>| <bkc at Murkworks.com> wrote:
>| >>>> class x(object):
>| >...  pass
>| >...
>| >>>> y = x()
>| >>>> type(y)
>| ><class '__main__.x'>
>| 
>| Is this a bug?  Is x a meta class?
>
>no, it is a regular (new-style) class.
>
>| >>> y.__class__ 
>| <class '__main__.x'>
>| >>> z = y()
>| Traceback (most recent call last):
>|   File "<stdin>", line 1, in ?
>| TypeError: 'x' object is not callable
>
>| Is y a class?  I'm puzzled ...
>
>no, it is an is an instance of x (and by implication, its type
>is x).

Ah, of course, type(y) is x.  I was excited about this just a few days ago,
but I guess playing with the old style class at the same time really
confuses one's mind.

I'm still finding my way around the new style classes, but I'd say that it
alone is worth the upgrade to 2.2.  Similarly nested scope is worth 2.1 and
list comprehension and augmented assignment is worth 2.0 for me.   

Huaiyu



More information about the Python-list mailing list