why does this fail on python 2.2?

Shalabh Chaturvedi shalabh at cafepy.com
Mon Aug 30 22:49:28 EDT 2004


John Hunter wrote:
> I'm trying to understand why some code from a module I'm using is
> failing on 2.3 but working on 2.3.  Here is the minimal example that
> replicates the problem
> 
> class Results(object):
>     __slots__ = ( "__doinit" )
>     def __new__(cls):
>         retobj = object.__new__(cls)
>         retobj.__doinit = True
>         return retobj
> 
> x = Results()
> 
> On python2.2, this fails with
> 
> mother:~/tmp> python2.2 test.py
> Traceback (most recent call last):
>   File "test.py", line 8, in ?
>     x = Results()
>   File "test.py", line 5, in __new__
>     retobj.__doinit = True
> AttributeError: 'Results' object has no attribute '_Results__doinit'

Since mangling slots was a feature added in 2.3:

http://sourceforge.net/tracker/index.php?func=detail&aid=569257&group_id=5470&atid=105470
http://sourceforge.net/tracker/index.php?func=detail&aid=671439&group_id=5470&atid=105470

Looking for keyword __slots__ and closed issues in the sf tracker led me 
to the above.

--
Shalabh





More information about the Python-list mailing list