summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-12-04 07:32:25 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-12-04 07:32:25 (GMT)
commitb02bb5ed0a45571c3be195cd053bb28e408a99cd (patch)
treed42cba22585a0e578fb78e1473bf377a398891b3 /Lib/test
parent21d77f5e9cd77c4fb45038ed778306a1ec4ecfb9 (diff)
downloadcpython-b02bb5ed0a45571c3be195cd053bb28e408a99cd.zip
cpython-b02bb5ed0a45571c3be195cd053bb28e408a99cd.tar.gz
cpython-b02bb5ed0a45571c3be195cd053bb28e408a99cd.tar.bz2
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.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_types.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 9cfc680..1e982d1 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -558,6 +558,13 @@ if type(dictlike.fromkeys('a')) is not dictlike:
raise TestFailed, 'dictsubclass.fromkeys created wrong type'
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}
if d.copy() != {1:1, 2:2, 3:3}: raise TestFailed, 'dict copy'