summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-02-27 00:15:55 (GMT)
committerBrett Cannon <bcannon@gmail.com>2007-02-27 00:15:55 (GMT)
commitba7bf49a54223b940b773c8678ab8c60da12a155 (patch)
tree48a0d5941089fdf3a1bc926ac6b94be26c84529e /Lib
parent44c526174d9296ce358ccee9652382e7ea5377f4 (diff)
downloadcpython-ba7bf49a54223b940b773c8678ab8c60da12a155.zip
cpython-ba7bf49a54223b940b773c8678ab8c60da12a155.tar.gz
cpython-ba7bf49a54223b940b773c8678ab8c60da12a155.tar.bz2
Remove the ability to slice/index on exceptions per PEP 352.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ConfigParser.py2
-rwxr-xr-xLib/test/test_dbm.py2
-rw-r--r--Lib/test/test_exceptions.py7
-rw-r--r--Lib/test/test_file.py2
-rw-r--r--Lib/test/test_pep352.py16
-rw-r--r--Lib/traceback.py2
6 files changed, 13 insertions, 18 deletions
diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py
index e080fcb..9a365c0 100644
--- a/Lib/ConfigParser.py
+++ b/Lib/ConfigParser.py
@@ -569,7 +569,7 @@ class ConfigParser(RawConfigParser):
value = value % vars
except KeyError as e:
raise InterpolationMissingOptionError(
- option, section, rawval, e[0])
+ option, section, rawval, e.message)
else:
break
if "%(" in value:
diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py
index a3b7716..ebe37b4 100755
--- a/Lib/test/test_dbm.py
+++ b/Lib/test/test_dbm.py
@@ -17,7 +17,7 @@ def cleanup():
try:
os.unlink(filename + suffix)
except OSError as e:
- (errno, strerror) = e
+ (errno, strerror) = e.errno, e.strerror
# if we can't delete the file because of permissions,
# nothing will work, so skip the test
if errno == 1:
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 0ff3b10..c0a5094 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -302,13 +302,6 @@ class ExceptionTests(unittest.TestCase):
'pickled "%r", attribute "%s' %
(e, checkArgName))
- def testSlicing(self):
- # Test that you can slice an exception directly instead of requiring
- # going through the 'args' attribute.
- args = (1, 2, 3)
- exc = BaseException(*args)
- self.failUnlessEqual(exc[:], args)
-
def testKeywordArgs(self):
# test that builtin exception don't take keyword args,
# but user-defined subclasses can if they want
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index 7eb052b..a57ab43 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -156,7 +156,7 @@ class OtherFileTests(unittest.TestCase):
try:
f = open(TESTFN, bad_mode)
except ValueError as msg:
- if msg[0] != 0:
+ if msg.message != 0:
s = str(msg)
if s.find(TESTFN) != -1 or s.find(bad_mode) == -1:
self.fail("bad error message for invalid mode: %s" % s)
diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py
index 2a6bac1..1f72ead 100644
--- a/Lib/test/test_pep352.py
+++ b/Lib/test/test_pep352.py
@@ -15,7 +15,7 @@ class ExceptionClassTests(unittest.TestCase):
self.failUnless(issubclass(Exception, object))
def verify_instance_interface(self, ins):
- for attr in ("args", "message", "__str__", "__repr__", "__getitem__"):
+ for attr in ("args", "message", "__str__", "__repr__"):
self.failUnless(hasattr(ins, attr), "%s missing %s attribute" %
(ins.__class__.__name__, attr))
@@ -72,8 +72,7 @@ class ExceptionClassTests(unittest.TestCase):
inheritance_tree.close()
self.failUnlessEqual(len(exc_set), 0, "%s not accounted for" % exc_set)
- interface_tests = ("length", "args", "message", "str", "unicode", "repr",
- "indexing")
+ interface_tests = ("length", "args", "message", "str", "unicode", "repr")
def interface_test_driver(self, results):
for test_name, (given, expected) in zip(self.interface_tests, results):
@@ -86,7 +85,7 @@ class ExceptionClassTests(unittest.TestCase):
exc = Exception(arg)
results = ([len(exc.args), 1], [exc.args[0], arg], [exc.message, arg],
[str(exc), str(arg)], [unicode(exc), unicode(arg)],
- [repr(exc), exc.__class__.__name__ + repr(exc.args)], [exc[0], arg])
+ [repr(exc), exc.__class__.__name__ + repr(exc.args)])
self.interface_test_driver(results)
def test_interface_multi_arg(self):
@@ -97,8 +96,7 @@ class ExceptionClassTests(unittest.TestCase):
results = ([len(exc.args), arg_count], [exc.args, args],
[exc.message, ''], [str(exc), str(args)],
[unicode(exc), unicode(args)],
- [repr(exc), exc.__class__.__name__ + repr(exc.args)],
- [exc[-1], args[-1]])
+ [repr(exc), exc.__class__.__name__ + repr(exc.args)])
self.interface_test_driver(results)
def test_interface_no_arg(self):
@@ -106,7 +104,7 @@ class ExceptionClassTests(unittest.TestCase):
exc = Exception()
results = ([len(exc.args), 0], [exc.args, tuple()], [exc.message, ''],
[str(exc), ''], [unicode(exc), u''],
- [repr(exc), exc.__class__.__name__ + '()'], [True, True])
+ [repr(exc), exc.__class__.__name__ + '()'])
self.interface_test_driver(results)
class UsageTests(unittest.TestCase):
@@ -166,6 +164,10 @@ class UsageTests(unittest.TestCase):
self.catch_fails(NonBaseException)
self.catch_fails(NonBaseException())
+ def test_catch_BaseException_instance(self):
+ # Catching an instance of a BaseException subclass won't work.
+ self.catch_fails(BaseException())
+
def test_catch_string(self):
# Catching a string is bad.
self.catch_fails("spam")
diff --git a/Lib/traceback.py b/Lib/traceback.py
index a0d2dcc..437e29b 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -178,7 +178,7 @@ def format_exception_only(etype, value):
# It was a syntax error; show exactly where the problem was found.
lines = []
try:
- msg, (filename, lineno, offset, badline) = value
+ msg, (filename, lineno, offset, badline) = value.args
except Exception:
pass
else: