[Python-checkins] python/dist/src/Lib/test test_types.py,1.49,1.50

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Thu, 24 Apr 2003 09:53:18 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv13553/Lib/test

Modified Files:
	test_types.py 
Log Message:
SF bug 665835: filter() treatment of str and tuple inconsistent

As a side issue on this bug, it was noted that list and tuple iterators
used macros to directly access containers and would not recognize
__getitem__ overrides.  If the method is overridden, the patch returns
a generic sequence iterator which calls the __getitem__ method; otherwise,
it returns a high custom iterator with direct access to container elements.


Index: test_types.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_types.py,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** test_types.py	19 Apr 2003 18:15:07 -0000	1.49
--- test_types.py	24 Apr 2003 16:52:45 -0000	1.50
***************
*** 257,260 ****
--- 257,266 ----
  vereq(list(tuple(f())), range(1000))
  
+ # Verify that __getitem__ overrides are recognized by __iter__
+ class T(tuple):
+   def __getitem__(self, key):
+      return str(key) + '!!!'
+ vereq(iter(T()).next(), '0!!!')
+ 
  print '6.5.3 Lists'
  # calling built-in types without argument must return empty
***************
*** 447,450 ****
--- 453,462 ----
  a[::2] = tuple(range(5))
  vereq(a, [0, 1, 1, 3, 2, 5, 3, 7, 4, 9])
+ 
+ # Verify that __getitem__ overrides are recognized by __iter__
+ class L(list):
+   def __getitem__(self, key):
+      return str(key) + '!!!'
+ vereq(iter(L()).next(), '0!!!')