summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-04-18 18:06:20 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-04-18 18:06:20 (GMT)
commitafb2c80b29897fba37bfca718df6c4b25c25a166 (patch)
tree0b7d9447ab2581f9ff9355df64444a0b9161a13f /Lib
parent16af557ae9c660cbd728546dcb28ec95b0030991 (diff)
downloadcpython-afb2c80b29897fba37bfca718df6c4b25c25a166.zip
cpython-afb2c80b29897fba37bfca718df6c4b25c25a166.tar.gz
cpython-afb2c80b29897fba37bfca718df6c4b25c25a166.tar.bz2
ceval.c/do_raise(): Tighten the test to disallow raising an instance of
a str subclass. test_descr.py/string_exceptions(): New sub-test. For 2.3 only. Guido doesn't want this backported.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_descr.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 308ed44..353d0f2 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2974,6 +2974,31 @@ def docdescriptor():
vereq(NewClass.__doc__, 'object=None; type=NewClass')
vereq(NewClass().__doc__, 'object=NewClass instance; type=NewClass')
+def string_exceptions():
+ if verbose:
+ print "Testing string exceptions ..."
+
+ # Ensure builtin strings work OK as exceptions.
+ astring = "An exception string."
+ try:
+ raise astring
+ except astring:
+ pass
+ else:
+ raise TestFailed, "builtin string not usable as exception"
+
+ # Ensure string subclass instances do not.
+ class MyStr(str):
+ pass
+
+ newstring = MyStr("oops -- shouldn't work")
+ try:
+ raise newstring
+ except TypeError:
+ pass
+ except:
+ raise TestFailed, "string subclass allowed as exception"
+
def test_main():
class_docstrings()
lists()
@@ -3039,6 +3064,7 @@ def test_main():
funnynew()
imulbug()
docdescriptor()
+ string_exceptions()
if verbose: print "All OK"
if __name__ == "__main__":