summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
Diffstat (limited to 'coverage')
-rw-r--r--coverage/backward.py17
-rw-r--r--coverage/execfile.py8
2 files changed, 4 insertions, 21 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index 8237d01b..a0dc9027 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -45,23 +45,6 @@ else:
"""Produce the items from dict `d`."""
return d.iteritems()
-# Exec is a statement in Py2, a function in Py3
-if sys.version_info >= (3, 0):
- def exec_code_object(code, global_map):
- """A wrapper around exec()."""
- exec(code, global_map)
-else:
- # OK, this is pretty gross. In Py2, exec was a statement, but that will
- # be a syntax error if we try to put it in a Py3 file, even if it is never
- # executed. So hide it inside an evaluated string literal instead.
- eval(
- compile(
- "def exec_code_object(code, global_map):\n"
- " exec code in global_map\n",
- "<exec_function>", "exec"
- )
- )
-
# Reading Python source and interpreting the coding comment is a big deal.
if sys.version_info >= (3, 0):
# Python 3.2 provides `tokenize.open`, the best way to open source files.
diff --git a/coverage/execfile.py b/coverage/execfile.py
index f90096e9..7b90137a 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -2,7 +2,7 @@
import imp, marshal, os, sys
-from coverage.backward import exec_code_object, open_source
+from coverage.backward import open_source
from coverage.misc import ExceptionDuringRun, NoCode, NoSource
@@ -99,7 +99,7 @@ def run_python_file(filename, args, package=None):
# Execute the code object.
try:
- exec_code_object(code, main_mod.__dict__)
+ exec(code, main_mod.__dict__)
except SystemExit:
# The user called sys.exit(). Just pass it along to the upper
# layers, where it will be handled.
@@ -107,11 +107,11 @@ def run_python_file(filename, args, package=None):
except:
# Something went wrong while executing the user code.
# Get the exc_info, and pack them into an exception that we can
- # throw up to the outer loop. We peel two layers off the traceback
+ # throw up to the outer loop. We peel one layer off the traceback
# so that the coverage.py code doesn't appear in the final printed
# traceback.
typ, err, tb = sys.exc_info()
- raise ExceptionDuringRun(typ, err, tb.tb_next.tb_next)
+ raise ExceptionDuringRun(typ, err, tb.tb_next)
finally:
# Restore the old __main__
sys.modules['__main__'] = old_main_mod