Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
2bef5857
Kaydet (Commit)
2bef5857
authored
Ock 26, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #18518: timeit now rejects statements which can't be compiled outside
a function or a loop (e.g. "return" or "break").
üst
21d7533c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
6 deletions
+21
-6
timeit.rst
Doc/library/timeit.rst
+0
-6
test_timeit.py
Lib/test/test_timeit.py
+12
-0
timeit.py
Lib/timeit.py
+6
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/timeit.rst
Dosyayı görüntüle @
2bef5857
...
@@ -64,12 +64,6 @@ The module defines three convenience functions and a public class:
...
@@ -64,12 +64,6 @@ The module defines three convenience functions and a public class:
Create a :class:`Timer` instance with the given statement, *setup* code and
Create a :class:`Timer` instance with the given statement, *setup* code and
*timer* function and run its :meth:`.timeit` method with *number* executions.
*timer* function and run its :meth:`.timeit` method with *number* executions.
.. note::
Because :meth:`.timeit` is executing *stmt*, placing a return statement
in *stmt* will prevent :meth:`.timeit` from returning execution time.
It will instead return the data specified by your return statement.
.. function:: repeat(stmt='pass', setup='pass', timer=<default timer>, repeat=3, number=1000000)
.. function:: repeat(stmt='pass', setup='pass', timer=<default timer>, repeat=3, number=1000000)
...
...
Lib/test/test_timeit.py
Dosyayı görüntüle @
2bef5857
...
@@ -73,9 +73,21 @@ class TestTimeit(unittest.TestCase):
...
@@ -73,9 +73,21 @@ class TestTimeit(unittest.TestCase):
def
test_timer_invalid_stmt
(
self
):
def
test_timer_invalid_stmt
(
self
):
self
.
assertRaises
(
ValueError
,
timeit
.
Timer
,
stmt
=
None
)
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
=
'yield from ()'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
stmt
=
'break'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
stmt
=
'continue'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
stmt
=
'from timeit import *'
)
def
test_timer_invalid_setup
(
self
):
def
test_timer_invalid_setup
(
self
):
self
.
assertRaises
(
ValueError
,
timeit
.
Timer
,
setup
=
None
)
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
=
'yield from ()'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
setup
=
'break'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
setup
=
'continue'
)
self
.
assertRaises
(
SyntaxError
,
timeit
.
Timer
,
setup
=
'from timeit import *'
)
fake_setup
=
"import timeit; timeit._fake_timer.setup()"
fake_setup
=
"import timeit; timeit._fake_timer.setup()"
fake_stmt
=
"import timeit; timeit._fake_timer.inc()"
fake_stmt
=
"import timeit; timeit._fake_timer.inc()"
...
...
Lib/timeit.py
Dosyayı görüntüle @
2bef5857
...
@@ -109,6 +109,12 @@ class Timer:
...
@@ -109,6 +109,12 @@ class Timer:
self
.
timer
=
timer
self
.
timer
=
timer
ns
=
{}
ns
=
{}
if
isinstance
(
stmt
,
str
):
if
isinstance
(
stmt
,
str
):
# Check that the code can be compiled outside a function
if
isinstance
(
setup
,
str
):
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
)
stmt
=
reindent
(
stmt
,
8
)
if
isinstance
(
setup
,
str
):
if
isinstance
(
setup
,
str
):
setup
=
reindent
(
setup
,
4
)
setup
=
reindent
(
setup
,
4
)
...
...
Misc/NEWS
Dosyayı görüntüle @
2bef5857
...
@@ -50,6 +50,9 @@ Core and Builtins
...
@@ -50,6 +50,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #18518: timeit now rejects statements which can'
t
be
compiled
outside
a
function
or
a
loop
(
e
.
g
.
"return"
or
"break"
).
-
Issue
#
23094
:
Fixed
readline
with
frames
in
Python
implementation
of
pickle
.
-
Issue
#
23094
:
Fixed
readline
with
frames
in
Python
implementation
of
pickle
.
-
Issue
#
23268
:
Fixed
bugs
in
the
comparison
of
ipaddress
classes
.
-
Issue
#
23268
:
Fixed
bugs
in
the
comparison
of
ipaddress
classes
.
...
...
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