[Python-checkins] python/dist/src/Lib/test test_types.py,1.41,1.42

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Tue, 03 Dec 2002 23:32:28 -0800


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

Modified Files:
	test_types.py 
Log Message:
Replace BadInternalCall with TypeError.  Add a test case.  Fix whitespace.

Just van Rossum showed a weird, but clever way for pure python code to 
trigger the BadInternalCall.  The C code had assumed that calling a class
constructor would return an instance of that class; however, classes that
abuse __new__ can invalidate that assumption.



Index: test_types.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_types.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** test_types.py	27 Nov 2002 07:29:33 -0000	1.41
--- test_types.py	4 Dec 2002 07:32:25 -0000	1.42
***************
*** 559,562 ****
--- 559,569 ----
  if type(dictlike().fromkeys('a')) is not dictlike:
      raise TestFailed, 'dictsubclass.fromkeys created wrong type'
+ from UserDict import UserDict
+ class mydict(dict):
+     def __new__(cls, *args, **kwargs):
+         return UserDict(*args, **kwargs)
+ try: mydict.fromkeys('a b c'.split())
+ except TypeError: pass
+ else: raise TestFailed, 'dict.fromkeys() failed to detect non-dict class.'
  # dict.copy()
  d = {1:1, 2:2, 3:3}