Copy with __slots__...will it ever work?
andrewsterian at yahoo.com
Fri Mar 28 16:48:32 CET 2003
Alex Martelli <aleax at aleax.it> wrote in message news:<VvWga.31967$i26.825094 at news2.tin.it>...
> Andrew Sterian wrote:
> > I've run up against the problem of not being able to call copy.copy()
> > on a new-style class that defines __slots__. I found the thread that
> Do you mean on an INSTANCE of the class, or on the class itself as
> you say?
Doh! Yes, I meant the instance.
> I'm not being uselessly pedantic, please note: since classes ARE
> "first-class objects" in Python, you can subject them to all
> kinds of operations (or at least TRY to;-), so saying "doing
> something to a class" and "doing something to instances of a
> class" are BOTH valid things, and two VERY different ones. People
> whose background is in languages where classes AREN'T "first-class
> objects", such as C++, often trip on this terminology issue.
I appreciate the distinction and you are not being uselessly pedantic.
Coming from C++ (a long time ago...and I'm so glad Python was there
to rescue me from the horror that is the STL) I always use
interchangeably, even though it's wrong. If people remind me often
enough, eventually I'll get it.
> They are -- but copying INSTANCES of the class isn't all that
> orthogonal, because if the class defines __slots__ then its
> instances hold state in a completely different way from how
> instances of other kinds of classes hold it.
Oh...OK...I didn't know that.
> Perhaps this makes it easier to see why "changing the strategy
> that instances use to keep their state" can easily interfere
> with "how to copy all the state of an instance". Not an intentional
> design decision, but a well-understandable bug (now fixed).
Thank you for the education. I can certainly wait until Python 2.3 is
released to have a fix for this.
More information about the Python-list