On 2/20/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote: > Have you considered the third alternative that's been > mentioned -- a wrapper? I don't like that at all. It's quite tricky to implement a fully transparent wrapper that supports all the special methods (__setitem__ etc.). It will be slower. And it will be more cumbersome to use. > The issue of __contains__ etc. could be sidestepped by > not giving the wrapper a __contains__ method at all. > If you want to do an 'in' test you do it on the > underlying dict, and then the semantics are clear. The semantics of defaultdict are crystal clear. __contains__(), keys() and friends represent the *actual*, *current* keys. Only __getitem__() calls on_missing() when the key is not present; being a "hook", on_missing() can do whatever it wants. What's the practical use case for not wanting __contains__() to function? All I hear is fear of theoretical bugs. -- --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4