This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "in" operator bug ?
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: bolzonella, tim.peters
Priority: normal Keywords:

Created on 2005-02-07 09:16 by bolzonella, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg24186 - (view) Author: Andrea Bolzonella (bolzonella) Date: 2005-02-07 09:16
my python : 
Python 2.4 (#1, Dec  8 2004, 18:57:30) 
[GCC 3.3.3 (SuSE Linux)] on linux 
 
>>class C(object): 
>>   def __getitem__ (self, name): 
>>         return 1 
 
>> c =C() 
 
>> 'a' in c 
 
here python never returns and CPU 100% 
 
this version works: 
>>class C(object): 
>>   def __getitem__ (self, name): 
>>         raise StopIteration 
 
>> c =C() 
 
>> 'a' in c 
False 
msg24187 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2005-02-07 14:56
Logged In: YES 
user_id=31435

Not a bug.  See the docs, or ask on comp.lang.python, for 
how __getitem__ works.  Your original C is a class such that c
[i] == 1 for any instance c and any subscript i.  So "1 in c" 
will return True quickly, but nothing else can succeed.  Add

	if name % 100000 == 0:
		print 'getting', name

at the start of your original __getitem__ for a clue.
History
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41541
2005-02-07 09:16:32bolzonellacreate