summaryrefslogtreecommitdiffstats
path: root/Lib/timeit.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-30 16:38:26 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-30 16:38:26 (GMT)
commitf28fa66351fe93b3fcdc98c7f35f05573ea93df2 (patch)
tree9590adf739f5f3b76111a8cc339ef9ab7b490a67 /Lib/timeit.py
parentfa494fd88384acc52cf9292d0c89e2961c8f747f (diff)
downloadcpython-f28fa66351fe93b3fcdc98c7f35f05573ea93df2.zip
cpython-f28fa66351fe93b3fcdc98c7f35f05573ea93df2.tar.gz
cpython-f28fa66351fe93b3fcdc98c7f35f05573ea93df2.tar.bz2
Issue #5633: Fixed timeit when the statement is a string and the setup is not.
Diffstat (limited to 'Lib/timeit.py')
-rwxr-xr-xLib/timeit.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/timeit.py b/Lib/timeit.py
index cf7446d..0b1c601 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")