[Python-Dev] defaultdict proposal round three (original) (raw)
Guido van Rossum guido at python.org
Tue Feb 21 03:12:50 CET 2006
- Previous message: [Python-Dev] defaultdict proposal round three
- Next message: [Python-Dev] defaultdict proposal round three
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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/)
- Previous message: [Python-Dev] defaultdict proposal round three
- Next message: [Python-Dev] defaultdict proposal round three
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]