summaryrefslogtreecommitdiff
path: root/Lib/timeit.py
diff options
context:
space:
mode:
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 5971d378ca..38077941fe 100755
--- a/Lib/timeit.py
+++ b/Lib/timeit.py
@@ -115,6 +115,12 @@ class Timer:
local_ns = {}
global_ns = _globals() if globals is None else globals
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)