This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Retro, brian.curtin, eli.bendersky, eric.araujo, eric.smith, georg.brandl, giampaolo.rodola, ncoghlan, rhettinger, terry.reedy, xuanji, ysj.ray
Date 2011-03-01.08:01:41
SpamBayes Score 5.314582e-12
Marked as misclassified No
Message-id <>
> Hmm, shouldn't self.__class__(self) be a 
> good default implementation of copy()?
> I'd expect any sequence to support this way 
> of creation from another sequence, even if it's inefficient.

The copy() method isn't being proposed for MutableSequence because it presumes that we know something about the constructor's signature.  For example, the constructor of array() needs the element storage type as an argument.  We refuse the temptation to guess.

In the Set api, we had no choice because many set-methods necessarily create a new set.  To handle the constructor signature problem, the creation step was factored-out into the from_iterable() method so that a user could override it if necessary.

Also copy() is handled oddly in the builtin types.  To handle the constructor signature issue for subclasses, they ignore the subclass and return a instance of the base class.  For example, the inherited copy() method on a subclass of list or dict will create an instance of list or dict, not of the subclass itself.  Accordingly, subclasses that want instances of themselves have to override the inherited copy() method.  They would have to do this anyway if they subclass contained any other data in the class dictionary that would need to be passed along to a copy.

In short, we're better-off not supplying copy() as part of the MutableSequence ABC.
Date User Action Args
2011-03-01 08:01:42rhettingersetrecipients: + rhettinger, georg.brandl, terry.reedy, ncoghlan, eric.smith, giampaolo.rodola, eric.araujo, Retro, eli.bendersky, brian.curtin, ysj.ray, xuanji
2011-03-01 08:01:42rhettingersetmessageid: <>
2011-03-01 08:01:42rhettingerlinkissue10516 messages
2011-03-01 08:01:41rhettingercreate