Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread rconradharris
A co-worker of mine came across some interesting behavior in the Python interpreter today and I'm hoping someone more knowledgeable in Python internals can explain this to me. First, we create an instance of an Old-Style class without defining a __contains__ but instead define a __getitem__

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Gabriel Genellina
En Wed, 11 Apr 2007 20:37:35 -0300, [EMAIL PROTECTED] escribió: First, we create an instance of an Old-Style class without defining a __contains__ but instead define a __getitem__ method in which we raise KeyError. Next we repeatedly use the 'in' operator to test to see whether something, a

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Steven D'Aprano
On Wed, 11 Apr 2007 16:37:35 -0700, rconradharris wrote: A co-worker of mine came across some interesting behavior in the Python interpreter today and I'm hoping someone more knowledgeable in Python internals can explain this to me. First, we create an instance of an Old-Style class without

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Steven D'Aprano
On Thu, 12 Apr 2007 00:32:32 -0300, Gabriel Genellina wrote: First I want to say that __getitem__ should raise IndexError, not KeyError, to indicate not found How do you know the Original Poster's class was meant to be a sequence rather than a mapping? -- Steven. --

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Scott David Daniels
Steven D'Aprano wrote: On Wed, 11 Apr 2007 16:37:35 -0700, rconradharris wrote: ... Here are the results under Python 2.5: tester(10) Checking index 0... Checking index 0... Checking index 0... Checking index 0... Checking index 0... [False, 'KeyError', False, 'KeyError', False,

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Gabriel Genellina
En Thu, 12 Apr 2007 01:23:08 -0300, Steven D'Aprano [EMAIL PROTECTED] escribió: On Thu, 12 Apr 2007 00:32:32 -0300, Gabriel Genellina wrote: First I want to say that __getitem__ should raise IndexError, not KeyError, to indicate not found How do you know the Original Poster's class was