D
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 raise KeyError, I still get (as desired) 'key' in instance ==
False.
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.
Thank you,
Alan Isaac
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 raise KeyError, I still get (as desired) 'key' in instance ==
False.
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.
Thank you,
Alan Isaac