Re: __contains__ vs. __getitem__

2006-08-10 Thread Alex Martelli
Pedro Werneck <[EMAIL PROTECTED]> wrote: > On Wed, 09 Aug 2006 16:51:23 GMT > "David Isaac" <[EMAIL PROTECTED]> wrote: > > > Looking forward: > > Can I count on this independence of __getitem__ and __contains__? > > I would like to understand whether it will be safe to count on this > > behavior.

Re: __contains__ vs. __getitem__

2006-08-10 Thread Alex Martelli
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > David Isaac wrote: > >> Alan Isaac wrote: > >>> I have a subclass of dict where __getitem__ returns None rather than > >>> raising KeyError for missing keys. (The why of that is not important > > for > >>> this question.) > > > > "Bruno Desthuilli

Re: __contains__ vs. __getitem__

2006-08-10 Thread Bruno Desthuilliers
David Isaac wrote: >> Alan Isaac wrote: >>> I have a subclass of dict where __getitem__ returns None rather than >>> raising KeyError for missing keys. (The why of that is not important > for >>> this question.) > > "Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote: >> Well, actually it may be impo

Re: __contains__ vs. __getitem__

2006-08-09 Thread Pedro Werneck
On Wed, 09 Aug 2006 16:51:23 GMT "David Isaac" <[EMAIL PROTECTED]> wrote: > Looking forward: > Can I count on this independence of __getitem__ and __contains__? > I would like to understand whether it will be safe to count on this > behavior. With the builtin 'dict' implementation, dict.__contai

Re: __contains__ vs. __getitem__

2006-08-09 Thread David Isaac
> Alan Isaac wrote: > > I have a subclass of dict where __getitem__ returns None rather than > > raising KeyError for missing keys. (The why of that is not important for > > this question.) "Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote: > Well, actually it may be important... What's so wrong wi

Re: __contains__ vs. __getitem__

2006-08-09 Thread enigmadude
That's a vague question, so the obligatory "it depends" response applies here. If you want to guard against the unexpected, perhaps it's a good idea to write unit tests rather than to take someone's word that it *should* work okay every time, in every case, no matter what you're doing with the dat

Re: __contains__ vs. __getitem__

2006-08-09 Thread Bruno Desthuilliers
David Isaac wrote: > I have a subclass of dict where __getitem__ returns None rather than > raising KeyError for missing keys. (The why of that is not important for > this question.) Well, actually it may be important... What's so wrong with d.get('key') that you need this behaviour ? -- http:/

__contains__ vs. __getitem__

2006-08-09 Thread David Isaac
I have a subclass of dict where __getitem__ returns None rather than raising KeyError for missing keys. (The why of that is not important for this question.) I was delighted to find that __contains__ still works as before after overriding __getitem__.So even though instance['key'] does not ra