summaryrefslogtreecommitdiffstats
path: root/Lib/timeit.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-01-26 10:09:17 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-01-26 10:09:17 (GMT)
commit2bef58577f1caa293a4843f4bdf245407825a61a (patch)
treeeab5b67eba2ad44a2e183962cfce9527cdfc8fcb /Lib/timeit.py
parent21d7533c4c13489b4b3baae59f9e25cd038fb16b (diff)
downloadcpython-2bef58577f1caa293a4843f4bdf245407825a61a.zip
cpython-2bef58577f1caa293a4843f4bdf245407825a61a.tar.gz
cpython-2bef58577f1caa293a4843f4bdf245407825a61a.tar.bz2
Issue #18518: timeit now rejects statements which can't be compiled outside
a function or a loop (e.g. "return" or "break").
Diffstat (limited to 'Lib/timeit.py')
-rwxr-xr-xLib/timeit.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/timeit.py b/Lib/timeit.py
index ead2030..9cec000 100755
--- a/Lib/timeit.py
+++ b/Lib/timeit.py
@@ -109,6 +109,12 @@ class Timer:
self.timer = timer
ns = {}
if isinstance(stmt, str):
+ # Check that the code can be compiled outside a function
+ if isinstance(setup, str):
+ compile(setup, dummy_src_name, "exec")
+ compile(setup + '\n' + stmt, dummy_src_name, "exec")
+ else:
+ compile(stmt, dummy_src_name, "exec")
stmt = reindent(stmt, 8)
if isinstance(setup, str):
setup = reindent(setup, 4)