Raymond Hettinger <[email protected]> added the comment:
> 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.
----------
nosy: +rhettinger
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue6326>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com