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 kristjan.jonsson, rhettinger
Date 2009-06-23.16:57:07
SpamBayes Score 2.84417e-08
Marked as misclassified No
Message-id <>
> One application of this is to make help a performance problem when one 
> wants to upgrade a list instance into a subclass instance.

Since this bypasses the subclass's __init__ and other methods, doesn't
it risk violating subclass invariants?

class CapList(list):
   def __init__(self, iterable=()):
       for elem in iterable:

class NoneCountingList(list):
   def __init__(self, iterable=()):
       list.__init__(self, iterable)
       self.nones = self.count(None)
   def append(self, value):
       list.append(self, value)
       self.nones += 1 if value is None else 0
   def extend(self, iterable):
       for elem in iterable:
   . . .

IOW, a swap() method is problematic for some subclasses because it
bypasses all of the subclass insertion/removal logic.  The problem is
compounded for subclasses written as C extensions because violating the
internal invariants may lead to a crash.
Date User Action Args
2009-06-23 16:57:09rhettingersetrecipients: + rhettinger, kristjan.jonsson
2009-06-23 16:57:09rhettingersetmessageid: <>
2009-06-23 16:57:08rhettingerlinkissue6326 messages
2009-06-23 16:57:07rhettingercreate