Message2849
a note of warning, Python doesn't properly define what other methods behavior is influenced by overriding some other methods, indeed in CPython the usual answer in most cases is none:
Python 2.4.3 (#1, Apr 7 2006, 10:54:33)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class X(dict):
... def has_key(self, k):
... return (k % 2) == 0
...
>>>
>>> x=X()
>>> x.has_key(4)
True
>>> 4 in x
False
the risk in not following CPython in this and try to be more useful, is to easily create cases where in some situations you get what you wanted but in other overriding cases you get infinite recursions.
|
|
Date |
User |
Action |
Args |
2008-02-20 17:18:48 | admin | link | issue1783803 messages |
2008-02-20 17:18:48 | admin | create | |
|