Message89633
> 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:
self.append(elem.upper())
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:
self.append(elem)
. . .
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:09 | rhettinger | set | recipients:
+ rhettinger, kristjan.jonsson |
2009-06-23 16:57:09 | rhettinger | set | messageid: <1245776229.73.0.772918114531.issue6326@psf.upfronthosting.co.za> |
2009-06-23 16:57:08 | rhettinger | link | issue6326 messages |
2009-06-23 16:57:07 | rhettinger | create | |
|