changeset: 96386:89de73c0d848 branch: 3.4 parent: 96376:8167df7d4cd0 user: Serhiy Storchaka date: Sat May 30 19:38:26 2015 +0300 files: Lib/test/test_timeit.py Lib/timeit.py Misc/NEWS description: Issue #5633: Fixed timeit when the statement is a string and the setup is not. diff -r 8167df7d4cd0 -r 89de73c0d848 Lib/test/test_timeit.py --- a/Lib/test/test_timeit.py Sat May 30 17:45:22 2015 +0300 +++ b/Lib/test/test_timeit.py Sat May 30 19:38:26 2015 +0300 @@ -124,6 +124,9 @@ def test_timeit_callable_stmt(self): self.timeit(self.fake_callable_stmt, self.fake_setup, number=3) + def test_timeit_callable_setup(self): + self.timeit(self.fake_stmt, self.fake_callable_setup, number=3) + def test_timeit_callable_stmt_and_setup(self): self.timeit(self.fake_callable_stmt, self.fake_callable_setup, number=3) @@ -173,6 +176,10 @@ self.repeat(self.fake_callable_stmt, self.fake_setup, repeat=3, number=5) + def test_repeat_callable_setup(self): + self.repeat(self.fake_stmt, self.fake_callable_setup, + repeat=3, number=5) + def test_repeat_callable_stmt_and_setup(self): self.repeat(self.fake_callable_stmt, self.fake_callable_setup, repeat=3, number=5) diff -r 8167df7d4cd0 -r 89de73c0d848 Lib/timeit.py --- a/Lib/timeit.py Sat May 30 17:45:22 2015 +0300 +++ b/Lib/timeit.py Sat May 30 19:38:26 2015 +0300 @@ -65,7 +65,7 @@ # in Timer.__init__() depend on setup being indented 4 spaces and stmt # being indented 8 spaces. template = """ -def inner(_it, _timer): +def inner(_it, _timer{init}): {setup} _t0 = _timer() for _i in _it: @@ -119,9 +119,10 @@ stmt = reindent(stmt, 8) if isinstance(setup, str): setup = reindent(setup, 4) - src = template.format(stmt=stmt, setup=setup) + src = template.format(stmt=stmt, setup=setup, init='') elif callable(setup): - src = template.format(stmt=stmt, setup='_setup()') + src = template.format(stmt=stmt, setup='_setup()', + init=', _setup=_setup') ns['_setup'] = setup else: raise ValueError("setup is neither a string nor callable") diff -r 8167df7d4cd0 -r 89de73c0d848 Misc/NEWS --- a/Misc/NEWS Sat May 30 17:45:22 2015 +0300 +++ b/Misc/NEWS Sat May 30 19:38:26 2015 +0300 @@ -60,6 +60,8 @@ Library ------- +- Issue #5633: Fixed timeit when the statement is a string and the setup is not. + - Issue #24326: Fixed audioop.ratecv() with non-default weightB argument. Original patch by David Moore.