Author arigo
Recipients
Date 2005-12-29.18:02:07
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=4771

Subclassing 'dict' to modify some behavior only works more
or less in CPython.  There are a lot of (admitedly
convoluted) ways to get unexpected effects, where the
original methods are called instead of the overridden ones.
And it's not future-proof: if new methods are added to 'dict'
in the future, say a merge() similar to update() but not
replacing existing keys, then they will need to be added to
that subclass as well, or the method will misbehave.  The
advantage of UserDict is to guard against all these problems.

For example, with the patch:

        exec "global a; a=5" in os.environ

stores the key 'a' directly in os.environ, bypassing
the custom __setitem__().  With UserDict instead, we
get an explicit error.  This is more a joke, but the
new-methods-appearing-later problem is more serious
IMHO.
History
Date User Action Args
2007-08-23 15:44:47adminlinkissue1367711 messages
2007-08-23 15:44:47admincreate