From ced770da07f9dbd7cc3afd09c2488c60faefe73c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 15 Jul 2015 22:11:36 +0300 Subject: Issue #24631: Fixed regression in the timeit modulu with multyline setup. --- Lib/timeit.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Lib/timeit.py') diff --git a/Lib/timeit.py b/Lib/timeit.py index d9f9563c2e..2de88f7271 100755 --- a/Lib/timeit.py +++ b/Lib/timeit.py @@ -109,19 +109,18 @@ class Timer: if isinstance(setup, str): # Check that the code can be compiled outside a function compile(setup, dummy_src_name, "exec") + stmtprefix = setup + '\n' setup = reindent(setup, 4) elif callable(setup): local_ns['_setup'] = setup init += ', _setup=_setup' + stmtprefix = '' setup = '_setup()' else: raise ValueError("setup is neither a string nor callable") if isinstance(stmt, str): # Check that the code can be compiled outside a function - if isinstance(setup, str): - compile(setup + '\n' + stmt, dummy_src_name, "exec") - else: - compile(stmt, dummy_src_name, "exec") + compile(stmtprefix + stmt, dummy_src_name, "exec") stmt = reindent(stmt, 8) elif callable(stmt): local_ns['_stmt'] = stmt -- cgit v1.2.1