diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 10:08:37 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 10:08:37 (GMT) |
commit | 73c086389a81f81d20a9f87eb95cebd15b6ced58 (patch) | |
tree | edec20b1b3a510fb68401f7c8cda0138dbc44db8 /Lib/timeit.py | |
parent | 001320720090976b8a44b2aaf7c5a10ce66f40b9 (diff) | |
download | cpython-73c086389a81f81d20a9f87eb95cebd15b6ced58.zip cpython-73c086389a81f81d20a9f87eb95cebd15b6ced58.tar.gz cpython-73c086389a81f81d20a9f87eb95cebd15b6ced58.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-x | Lib/timeit.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/timeit.py b/Lib/timeit.py index ef246ce..a8992f8 100755 --- a/Lib/timeit.py +++ b/Lib/timeit.py @@ -123,6 +123,12 @@ class Timer: self.timer = timer ns = {} if isinstance(stmt, basestring): + # Check that the code can be compiled outside a function + if isinstance(setup, basestring): + 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, basestring): setup = reindent(setup, 4) |