difference 2.3 versus 2.2

Michele Simionato mis6 at pitt.edu
Wed Jan 22 17:25:45 EST 2003


I have found a difference of behaviour between Python 2.2 and 2.3.

$ python
Python 2.2 (#1, Apr 12 2002, 15:29:57)
[GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Meta(type): pass
...
>>> class C(object): pass
...
>>> C.__class__=Meta
>>> C.__class__
<class '__main__.Meta'>

Therefore I can change the metaclass of C on Python 2.2.
However on Python 2.3:

$ p23a
Python 2.3a1 (#1, Jan  6 2003, 10:31:14)
[GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-108.7.2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Meta(type): pass
...
>>> class C(object): pass
...
>>> C.__class__=Meta
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: __class__ assignment: only for heap types

Can somebody put some light on this TypeError ? 
It looks like intentional.

I can change class of a normal object, why not the class of a class ?

Bye,

                  Michele




More information about the Python-list mailing list