Skip to content

Commit e250061

Browse files
Carreaugpshead
authored andcommitted
bpo-36895: remove time.clock() as per removal notice. (pythonGH-13270)
`time.clock()` was deprecated in 3.3, and marked for removal removal in 3.8; this thus remove it from the time module.
1 parent 5d23e28 commit e250061

File tree

4 files changed

+4
-69
lines changed

4 files changed

+4
-69
lines changed

Doc/library/time.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Functions
155155

156156
.. availability:: Windows, Unix. Not available on VxWorks.
157157

158-
.. deprecated:: 3.3
158+
.. deprecated-removed:: 3.3 3.8
159159
The behaviour of this function depends on the platform: use
160160
:func:`perf_counter` or :func:`process_time` instead, depending on your
161161
requirements, to have a well defined behaviour.

Lib/test/test_time.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,6 @@ def check_ns(sec, ns):
8888
check_ns(time.clock_gettime(time.CLOCK_REALTIME),
8989
time.clock_gettime_ns(time.CLOCK_REALTIME))
9090

91-
@unittest.skipUnless(hasattr(time, 'clock'),
92-
'need time.clock()')
93-
def test_clock(self):
94-
with self.assertWarns(DeprecationWarning):
95-
time.clock()
96-
97-
with self.assertWarns(DeprecationWarning):
98-
info = time.get_clock_info('clock')
99-
self.assertTrue(info.monotonic)
100-
self.assertFalse(info.adjustable)
101-
10291
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
10392
'need time.clock_gettime()')
10493
def test_clock_realtime(self):
@@ -553,15 +542,9 @@ def test_localtime_failure(self):
553542

554543
def test_get_clock_info(self):
555544
clocks = ['monotonic', 'perf_counter', 'process_time', 'time']
556-
if hasattr(time, 'clock'):
557-
clocks.append('clock')
558545

559546
for name in clocks:
560-
if name == 'clock':
561-
with self.assertWarns(DeprecationWarning):
562-
info = time.get_clock_info('clock')
563-
else:
564-
info = time.get_clock_info(name)
547+
info = time.get_clock_info(name)
565548

566549
#self.assertIsInstance(info, dict)
567550
self.assertIsInstance(info.implementation, str)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The function ``time.clock()`` was deprecated in 3.3 in favor of
2+
``time.perf_counter()`` and marked for removal in 3.8, it has removed.

Modules/timemodule.c

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -145,44 +145,6 @@ perf_counter(_Py_clock_info_t *info)
145145
return _PyFloat_FromPyTime(t);
146146
}
147147

148-
#if (defined(MS_WINDOWS) || defined(HAVE_CLOCK)) && !defined(__VXWORKS__)
149-
#define PYCLOCK
150-
static PyObject*
151-
pyclock(_Py_clock_info_t *info)
152-
{
153-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
154-
"time.clock has been deprecated in Python 3.3 and will "
155-
"be removed from Python 3.8: "
156-
"use time.perf_counter or time.process_time "
157-
"instead", 1) < 0) {
158-
return NULL;
159-
}
160-
161-
#ifdef MS_WINDOWS
162-
return perf_counter(info);
163-
#else
164-
_PyTime_t t;
165-
if (_PyTime_GetClockWithInfo(&t, info) < 0) {
166-
return NULL;
167-
}
168-
return _PyFloat_FromPyTime(t);
169-
#endif
170-
}
171-
172-
static PyObject *
173-
time_clock(PyObject *self, PyObject *unused)
174-
{
175-
return pyclock(NULL);
176-
}
177-
178-
PyDoc_STRVAR(clock_doc,
179-
"clock() -> floating point number\n\
180-
\n\
181-
Return the CPU time or real time since the start of the process or since\n\
182-
the first call to clock(). This has as much precision as the system\n\
183-
records.");
184-
#endif
185-
186148
#ifdef HAVE_CLOCK_GETTIME
187149
static PyObject *
188150
time_clock_gettime(PyObject *self, PyObject *args)
@@ -1477,15 +1439,6 @@ time_get_clock_info(PyObject *self, PyObject *args)
14771439
return NULL;
14781440
}
14791441
}
1480-
#ifdef PYCLOCK
1481-
else if (strcmp(name, "clock") == 0) {
1482-
obj = pyclock(&info);
1483-
if (obj == NULL) {
1484-
return NULL;
1485-
}
1486-
Py_DECREF(obj);
1487-
}
1488-
#endif
14891442
else if (strcmp(name, "monotonic") == 0) {
14901443
if (_PyTime_GetMonotonicClockWithInfo(&t, &info) < 0) {
14911444
return NULL;
@@ -1700,9 +1653,6 @@ init_timezone(PyObject *m)
17001653
static PyMethodDef time_methods[] = {
17011654
{"time", time_time, METH_NOARGS, time_doc},
17021655
{"time_ns", time_time_ns, METH_NOARGS, time_ns_doc},
1703-
#ifdef PYCLOCK
1704-
{"clock", time_clock, METH_NOARGS, clock_doc},
1705-
#endif
17061656
#ifdef HAVE_CLOCK_GETTIME
17071657
{"clock_gettime", time_clock_gettime, METH_VARARGS, clock_gettime_doc},
17081658
{"clock_gettime_ns",time_clock_gettime_ns, METH_VARARGS, clock_gettime_ns_doc},

0 commit comments

Comments
 (0)