summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2013-10-20 08:23:52 -0400
committerNed Batchelder <ned@nedbatchelder.com>2013-10-20 08:23:52 -0400
commit6dfbb755d1f6994ccec9ae56ad7f2eedad2ed0d6 (patch)
tree11be85589c7f72a5073ace06d563fafbf638b443
parent50959ccaaa07ccfb5a01cb38eb5d2b548e0dfe9a (diff)
downloadpython-coveragepy-git-6dfbb755d1f6994ccec9ae56ad7f2eedad2ed0d6.tar.gz
Except clause can now use 'as', no need for lots of sys.exc_info
--HG-- branch : 4.0
-rw-r--r--coverage/cmdline.py9
-rw-r--r--coverage/control.py3
-rw-r--r--coverage/execfile.py3
-rw-r--r--coverage/misc.py4
-rw-r--r--coverage/parser.py11
-rw-r--r--lab/parser.py3
-rw-r--r--setup.py7
-rw-r--r--tests/backunittest.py5
8 files changed, 16 insertions, 29 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 9ff29f3a..93732839 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -716,21 +716,18 @@ def main(argv=None):
argv = sys.argv[1:]
try:
status = CoverageScript().command_line(argv)
- except ExceptionDuringRun:
+ except ExceptionDuringRun as err:
# An exception was caught while running the product code. The
# sys.exc_info() return tuple is packed into an ExceptionDuringRun
# exception.
- _, err, _ = sys.exc_info()
traceback.print_exception(*err.args)
status = ERR
- except CoverageException:
+ except CoverageException as err:
# A controlled error inside coverage.py: print the message to the user.
- _, err, _ = sys.exc_info()
print(err)
status = ERR
- except SystemExit:
+ except SystemExit as err:
# The user called `sys.exit()`. Exit with their argument, if any.
- _, err, _ = sys.exc_info()
if err.args:
status = err.args[0]
else:
diff --git a/coverage/control.py b/coverage/control.py
index 466f76dd..51ff0439 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -98,8 +98,7 @@ class coverage(object):
config_file = ".coveragerc"
try:
self.config.from_file(config_file)
- except ValueError:
- _, err, _ = sys.exc_info()
+ except ValueError as err:
raise CoverageException(
"Couldn't read config file %s: %s" % (config_file, err)
)
diff --git a/coverage/execfile.py b/coverage/execfile.py
index aec65343..f90096e9 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -56,8 +56,7 @@ def run_python_module(modulename, args):
package = __import__(packagename, glo, loc, ['__path__'])
searchpath = package.__path__
openfile, pathname, _ = imp.find_module(name, searchpath)
- except ImportError:
- _, err, _ = sys.exc_info()
+ except ImportError as err:
raise NoSource(str(err))
finally:
if openfile:
diff --git a/coverage/misc.py b/coverage/misc.py
index 2a36d5c1..c3fd9e2a 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -3,7 +3,6 @@
import errno
import inspect
import os
-import sys
from coverage.backward import md5
from coverage.backward import string_class, to_bytes
@@ -97,8 +96,7 @@ def file_be_gone(path):
"""Remove a file, and don't get annoyed if it doesn't exist."""
try:
os.remove(path)
- except OSError:
- _, e, _ = sys.exc_info()
+ except OSError as e:
if e.errno != errno.ENOENT:
raise
diff --git a/coverage/parser.py b/coverage/parser.py
index d0fe9976..7e194705 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -1,6 +1,6 @@
"""Code parsing for Coverage."""
-import collections, dis, re, sys, token, tokenize
+import collections, dis, re, token, tokenize
from coverage.backward import StringIO
from coverage.backward import open_source, range # pylint: disable=W0622
@@ -27,8 +27,7 @@ class CodeParser(object):
try:
with open_source(self.filename) as sourcef:
self.text = sourcef.read()
- except IOError:
- _, err, _ = sys.exc_info()
+ except IOError as err:
raise NoSource(
"No source for code: '%s': %s" % (self.filename, err)
)
@@ -202,8 +201,7 @@ class CodeParser(object):
"""
try:
self._raw_parse()
- except (tokenize.TokenError, IndentationError):
- _, tokerr, _ = sys.exc_info()
+ except (tokenize.TokenError, IndentationError) as tokerr:
msg, lineno = tokerr.args
raise NotPython(
"Couldn't parse '%s' as Python source: '%s' at %s" %
@@ -333,8 +331,7 @@ class ByteParser(object):
# Python 2.3 and 2.4 don't like partial last lines, so be sure
# the text ends nicely for them.
self.code = compile(text + '\n', filename, "exec")
- except SyntaxError:
- _, synerr, _ = sys.exc_info()
+ except SyntaxError as synerr:
raise NotPython(
"Couldn't parse '%s' as Python source: '%s' at line %d" %
(filename, synerr.msg, synerr.lineno)
diff --git a/lab/parser.py b/lab/parser.py
index ce6902a6..7eaa9448 100644
--- a/lab/parser.py
+++ b/lab/parser.py
@@ -57,8 +57,7 @@ class ParserMain(object):
if options.dis or options.chunks:
try:
bp = ByteParser(filename=filename)
- except CoverageException:
- _, err, _ = sys.exc_info()
+ except CoverageException as err:
print("%s" % (err,))
return
diff --git a/setup.py b/setup.py
index 215102bd..e8780f3a 100644
--- a/setup.py
+++ b/setup.py
@@ -144,9 +144,9 @@ class ve_build_ext(build_ext):
build_ext.build_extension(self, ext)
except ext_errors:
raise BuildFailed()
- except ValueError:
+ except ValueError as err:
# this can happen on Windows 64 bit, see Python issue 7511
- if "'path'" in str(sys.exc_info()[1]): # works with both py 2/3
+ if "'path'" in str(err): # works with both py 2/3
raise BuildFailed()
raise
@@ -186,9 +186,8 @@ def main():
# extension. Try it with, and if it fails, try it without.
try:
setup(**setup_args)
- except BuildFailed:
+ except BuildFailed as exc:
msg = "Couldn't install with extension module, trying without it..."
- exc = sys.exc_info()[1]
exc_msg = "%s: %s" % (exc.__class__.__name__, exc.cause)
print("**\n** %s\n** %s\n**" % (msg, exc_msg))
diff --git a/tests/backunittest.py b/tests/backunittest.py
index 019e811c..16414014 100644
--- a/tests/backunittest.py
+++ b/tests/backunittest.py
@@ -1,6 +1,6 @@
"""Implementations of unittest features from the future."""
-import difflib, re, sys, unittest
+import difflib, re, unittest
def _need(method):
@@ -55,8 +55,7 @@ class TestCase(unittest.TestCase):
"""
try:
callobj(*args, **kw)
- except excClass:
- _, exc, _ = sys.exc_info()
+ except excClass as exc:
excMsg = str(exc)
if re.search(regexp, excMsg):
# Message provided, and we got the right one: it passes.