diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-30 19:38:26 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-30 19:38:26 +0300 |
commit | 02b73049675f388de1b33f81875b760f5a75cb5c (patch) | |
tree | 5f9d66009d2236fbb1a99ecf11636652d7e3aafd | |
parent | b6574f2b45715eec7d9f734f7116a2e370c8561c (diff) | |
download | cpython-02b73049675f388de1b33f81875b760f5a75cb5c.tar.gz |
Issue #5633: Fixed timeit when the statement is a string and the setup is not.
-rw-r--r-- | Lib/test/test_timeit.py | 7 | ||||
-rwxr-xr-x | Lib/timeit.py | 7 | ||||
-rw-r--r-- | Misc/NEWS | 2 |
3 files changed, 13 insertions, 3 deletions
diff --git a/Lib/test/test_timeit.py b/Lib/test/test_timeit.py index 09e76e023d..918a294c10 100644 --- a/Lib/test/test_timeit.py +++ b/Lib/test/test_timeit.py @@ -124,6 +124,9 @@ class TestTimeit(unittest.TestCase): 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 @@ class TestTimeit(unittest.TestCase): 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 --git a/Lib/timeit.py b/Lib/timeit.py index cf7446d8c1..0b1c601c97 100755 --- a/Lib/timeit.py +++ b/Lib/timeit.py @@ -65,7 +65,7 @@ default_timer = time.perf_counter # 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 @@ class Timer: 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") @@ -60,6 +60,8 @@ Core and Builtins 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. |