diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-22 20:35:45 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-22 20:35:45 -0500 |
commit | b007d17e5e2da220c57920b84c7f337bc8b378d0 (patch) | |
tree | 2aeb27234b8ba1c2ae7e25c2f73c370816e29b41 /coverage/backward.py | |
parent | bf001ce15db6a5847fa41919474d9d007d2d49d3 (diff) | |
download | python-coveragepy-b007d17e5e2da220c57920b84c7f337bc8b378d0.tar.gz |
Python source files that don't end with a newline can now be executed, fixing #47.
Diffstat (limited to 'coverage/backward.py')
-rw-r--r-- | coverage/backward.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/coverage/backward.py b/coverage/backward.py index af46e0d..425bcc6 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -51,19 +51,20 @@ except NameError: # Exec is a statement in Py2, a function in Py3 if sys.version_info >= (3, 0): - def exec_function(source, filename, global_map): + def exec_code_object(code, global_map): """A wrapper around exec().""" - exec(compile(source, filename, "exec"), global_map) + 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_function(source, filename, global_map): - exec compile(source, filename, "exec") in global_map -""", - "<exec_function>", "exec" - )) + eval( + compile( + "def exec_code_object(code, global_map):\n" + " exec code in global_map\n", + "<exec_function>", "exec" + ) + ) # ConfigParser was renamed to the more-standard configparser try: |