Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e82e14e2
Commit
e82e14e2
authored
Jan 26, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #18518: timeit now rejects statements which can't be compiled outside
a function or a loop (e.g. "return" or "break").
parent
6ff3e37a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
Lib/test/test_timeit.py
Lib/test/test_timeit.py
+8
-0
Lib/timeit.py
Lib/timeit.py
+6
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_timeit.py
View file @
e82e14e2
...
...
@@ -73,9 +73,17 @@ class TestTimeit(unittest.TestCase):
def
test_timer_invalid_stmt
(
self
):
self
.
assertRaises
(
ValueError
,
timeit
.
Timer
,
stmt
=
None
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
stmt
=
'return'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
stmt
=
'yield'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
stmt
=
'break'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
stmt
=
'continue'
)
def
test_timer_invalid_setup
(
self
):
self
.
assertRaises
(
ValueError
,
timeit
.
Timer
,
setup
=
None
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
setup
=
'return'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
setup
=
'yield'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
setup
=
'break'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
setup
=
'continue'
)
fake_setup
=
"import timeit; timeit._fake_timer.setup()"
fake_stmt
=
"import timeit; timeit._fake_timer.inc()"
...
...
Lib/timeit.py
View file @
e82e14e2
...
...
@@ -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
)
...
...
Misc/NEWS
View file @
e82e14e2
...
...
@@ -15,6 +15,9 @@ Core and Builtins
Library
-------
- Issue #18518: timeit now rejects statements which can'
t
be
compiled
outside
a
function
or
a
loop
(
e
.
g
.
"return"
or
"break"
).
-
Issue
#
19996
:
Make
:
mod
:`
httplib
`
ignore
headers
with
no
name
rather
than
assuming
the
body
has
started
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment