diff options
Diffstat (limited to 'Lib/timeit.py')
-rwxr-xr-x | Lib/timeit.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/timeit.py b/Lib/timeit.py index ead2030515..9cec000f73 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) |