Raymond Hettinger added the comment:

> This is a consequence of subclassing a builtin type

Not really.  This is how subclassing works in general.  Any time you a user 
calls a parent class directly on an instance of subclass, they are bypassing 
whatever the subclass needs to do to maintain its invariants.

class A:
    def __init__(self):
        self.data = []
    def add(self, x):
        self.data.append(x)

class B(A):
    'Track the number of odds'
    def __init__(self):
        A.__init__(self)
        self.odds = 0
    def add(self, x):
        A.add(self, x)
        self.odds += (x % 2)

b = B()
b.add(1)
b.add(2)
b.add(3)
b.add(4)
A.add(b, 5)
assert b.odds == sum(x%1 for x in b.data), 'OMG, B is broken!'

There is nothing special about OrderedDicts in this regard.  Perhaps there 
should be a FAQ entry regarding the "facts of life" in the world of object 
oriented programming.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to