Why does 2.3a2 change "slots" in complex?

David Mertz mertz at gnosis.cx
Sat Mar 1 04:03:45 CET 2003

Our gnosis.xml.pickle package makes an effort to pickle various objects,
generally trying even harder than the standard pickle module.  In
particular, we try to do sensible things with new-style classes that
have slots, and that don't.

One of the unit tests involves adding extra attributes to descendents of
standard data types.  It turns out, that test breaks with Python 2.3a2,
because of a change in the implementation of complex.

Here is a brief test case that shows the behavior.  I am interested in
why this change was made.  Is it a bug or a feature?  If a feature, what
benefit does this have?  If a bug... well, I guess that's the point of
an alpha version.

    % cat newstyle.py
    # Test of extra attributes in new-style classes
    import sys
    print sys.version

    class Int(int): pass
    i = Int(4)
    print i,
    i.attr = 5
    print i.attr

    class Complex(complex): pass
    c = Complex(1+1j)
    print c,
    c.attr = 2
    print c.attr

    % python22 newstyle.py
    2.2.2 (#0, Oct 24 2002, 20:53:04) [EMX GCC 2.8.1]
    4 5
    (1+1j) 2

    % python23a2 newstyle.py
    2.3a2 (#0, Feb 21 2003, 19:35:57) [EMX GCC 2.8.1]
    4 5
    Traceback (most recent call last):
      File "newstyle.py", line 14, in ?
        c.attr = 2
    AttributeError: 'complex' object has no attribute 'attr'

Yours, David...

 mertz@   _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i
gnosis  _/_/                    Postmodern Enterprises         _/_/  s r
.cx    _/_/  MAKERS OF CHAOS....                              _/_/   i u
      _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/    g s

More information about the Python-list mailing list