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 docs@python, eric.snow, rhettinger
Date 2015-07-25.17:31:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1437845482.22.0.0842881817283.issue24721@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2015-07-25 17:31:22rhettingersetrecipients: + rhettinger, docs@python, eric.snow
2015-07-25 17:31:22rhettingersetmessageid: <1437845482.22.0.0842881817283.issue24721@psf.upfronthosting.co.za>
2015-07-25 17:31:22rhettingerlinkissue24721 messages
2015-07-25 17:31:21rhettingercreate