Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b89fdf

Browse files
committed
PEP 418: Rename adjusted attribute to adjustable in time.get_clock_info() result
Fix also its value on Windows and Linux according to its documentation: "adjustable" indicates if the clock *can be* adjusted, not if it is or was adjusted. In most cases, it is not possible to indicate if a clock is or was adjusted.
1 parent bda4b88 commit 2b89fdf

6 files changed

Lines changed: 30 additions & 37 deletions

File tree

Doc/library/time.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ The module defines the following functions and data items:
255255

256256
The result has the following attributes:
257257

258-
- *adjusted*: ``True`` if the clock can be adjusted (e.g. by a NTP daemon),
259-
``False`` otherwise
258+
- *adjustable*: ``True`` if the clock can be changed automatically (e.g. by
259+
a NTP daemon) or manually by the system administrator, ``False`` otherwise
260260
- *implementation*: The name of the underlying C function used to get
261261
the clock value
262262
- *monotonic*: ``True`` if the clock cannot go backward,

Include/pytime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct {
2626
typedef struct {
2727
const char *implementation;
2828
int monotonic;
29-
int adjusted;
29+
int adjustable;
3030
double resolution;
3131
} _Py_clock_info_t;
3232

Lib/test/test_time.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def test_time(self):
3232
info = time.get_clock_info('time')
3333
self.assertFalse(info.monotonic)
3434
if sys.platform != 'win32':
35-
self.assertTrue(info.adjusted)
35+
self.assertTrue(info.adjustable)
3636

3737
def test_clock(self):
3838
time.clock()
3939

4040
info = time.get_clock_info('clock')
4141
self.assertTrue(info.monotonic)
42-
self.assertFalse(info.adjusted)
42+
self.assertFalse(info.adjustable)
4343

4444
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
4545
'need time.clock_gettime()')
@@ -372,9 +372,9 @@ def test_monotonic(self):
372372
info = time.get_clock_info('monotonic')
373373
self.assertTrue(info.monotonic)
374374
if sys.platform == 'linux':
375-
self.assertTrue(info.adjusted)
375+
self.assertTrue(info.adjustable)
376376
else:
377-
self.assertFalse(info.adjusted)
377+
self.assertFalse(info.adjustable)
378378

379379
def test_perf_counter(self):
380380
time.perf_counter()
@@ -390,7 +390,7 @@ def test_process_time(self):
390390

391391
info = time.get_clock_info('process_time')
392392
self.assertTrue(info.monotonic)
393-
self.assertFalse(info.adjusted)
393+
self.assertFalse(info.adjustable)
394394

395395
@unittest.skipUnless(hasattr(time, 'monotonic'),
396396
'need time.monotonic')
@@ -441,7 +441,7 @@ def test_get_clock_info(self):
441441
# 0.0 < resolution <= 1.0
442442
self.assertGreater(info.resolution, 0.0)
443443
self.assertLessEqual(info.resolution, 1.0)
444-
self.assertIsInstance(info.adjusted, bool)
444+
self.assertIsInstance(info.adjustable, bool)
445445

446446
self.assertRaises(ValueError, time.get_clock_info, 'xxx')
447447

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Core and Builtins
2121
Library
2222
-------
2323

24+
- Rename adjusted attribute to adjustable in time.get_clock_info() result.
25+
2426
- Issue #3518: Remove references to non-existent BaseManager.from_address()
2527
method.
2628

Modules/timemodule.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ floatclock(_Py_clock_info_t *info)
9696
info->implementation = "clock()";
9797
info->resolution = 1.0 / (double)CLOCKS_PER_SEC;
9898
info->monotonic = 1;
99-
info->adjusted = 0;
99+
info->adjustable = 0;
100100
}
101101
return PyFloat_FromDouble((double)value / CLOCKS_PER_SEC);
102102
}
@@ -132,7 +132,7 @@ win_perf_counter(_Py_clock_info_t *info, PyObject **result)
132132
info->implementation = "QueryPerformanceCounter()";
133133
info->resolution = 1.0 / (double)cpu_frequency;
134134
info->monotonic = 1;
135-
info->adjusted = 0;
135+
info->adjustable = 0;
136136
}
137137
*result = PyFloat_FromDouble(diff / (double)cpu_frequency);
138138
return 0;
@@ -882,7 +882,7 @@ pymonotonic(_Py_clock_info_t *info)
882882
return NULL;
883883
}
884884
info->resolution = timeIncrement * 1e-7;
885-
info->adjusted = 0;
885+
info->adjustable = 0;
886886
}
887887
return PyFloat_FromDouble(result);
888888

@@ -903,7 +903,7 @@ pymonotonic(_Py_clock_info_t *info)
903903
info->implementation = "mach_absolute_time()";
904904
info->resolution = (double)timebase.numer / timebase.denom * 1e-9;
905905
info->monotonic = 1;
906-
info->adjusted = 0;
906+
info->adjustable = 0;
907907
}
908908
return PyFloat_FromDouble(secs);
909909

@@ -926,13 +926,7 @@ pymonotonic(_Py_clock_info_t *info)
926926
struct timespec res;
927927
info->monotonic = 1;
928928
info->implementation = function;
929-
#if (defined(linux) || defined(__linux) || defined(__linux__)) \
930-
&& !defined(CLOCK_HIGHRES)
931-
/* CLOCK_MONOTONIC is adjusted on Linux */
932-
info->adjusted = 1;
933-
#else
934-
info->adjusted = 0;
935-
#endif
929+
info->adjustable = 0;
936930
if (clock_getres(clk_id, &res) == 0)
937931
info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
938932
else
@@ -1024,7 +1018,7 @@ py_process_time(_Py_clock_info_t *info)
10241018
info->implementation = "GetProcessTimes()";
10251019
info->resolution = 1e-7;
10261020
info->monotonic = 1;
1027-
info->adjusted = 0;
1021+
info->adjustable = 0;
10281022
}
10291023
return PyFloat_FromDouble(total * 1e-7);
10301024
#else
@@ -1053,7 +1047,7 @@ py_process_time(_Py_clock_info_t *info)
10531047
struct timespec res;
10541048
info->implementation = function;
10551049
info->monotonic = 1;
1056-
info->adjusted = 0;
1050+
info->adjustable = 0;
10571051
if (clock_getres(clk_id, &res) == 0)
10581052
info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
10591053
else
@@ -1071,7 +1065,7 @@ py_process_time(_Py_clock_info_t *info)
10711065
if (info) {
10721066
info->implementation = "getrusage(RUSAGE_SELF)";
10731067
info->monotonic = 1;
1074-
info->adjusted = 0;
1068+
info->adjustable = 0;
10751069
info->resolution = 1e-6;
10761070
}
10771071
return PyFloat_FromDouble(total);
@@ -1100,7 +1094,7 @@ py_process_time(_Py_clock_info_t *info)
11001094
if (info) {
11011095
info->implementation = "times()";
11021096
info->monotonic = 1;
1103-
info->adjusted = 0;
1097+
info->adjustable = 0;
11041098
info->resolution = 1.0 / ticks_per_second;
11051099
}
11061100
return PyFloat_FromDouble(total);
@@ -1137,12 +1131,12 @@ time_get_clock_info(PyObject *self, PyObject *args)
11371131
#ifdef Py_DEBUG
11381132
info.implementation = NULL;
11391133
info.monotonic = -1;
1140-
info.adjusted = -1;
1134+
info.adjustable = -1;
11411135
info.resolution = -1.0;
11421136
#else
11431137
info.implementation = "";
11441138
info.monotonic = 0;
1145-
info.adjusted = 0;
1139+
info.adjustable = 0;
11461140
info.resolution = 1.0;
11471141
#endif
11481142

@@ -1188,11 +1182,11 @@ time_get_clock_info(PyObject *self, PyObject *args)
11881182
goto error;
11891183
Py_CLEAR(obj);
11901184

1191-
assert(info.adjusted != -1);
1192-
obj = PyBool_FromLong(info.adjusted);
1185+
assert(info.adjustable != -1);
1186+
obj = PyBool_FromLong(info.adjustable);
11931187
if (obj == NULL)
11941188
goto error;
1195-
if (PyDict_SetItemString(dict, "adjusted", obj) == -1)
1189+
if (PyDict_SetItemString(dict, "adjustable", obj) == -1)
11961190
goto error;
11971191
Py_CLEAR(obj);
11981192

@@ -1471,7 +1465,7 @@ floattime(_Py_clock_info_t *info)
14711465
struct timespec res;
14721466
info->implementation = "clock_gettime(CLOCK_REALTIME)";
14731467
info->monotonic = 0;
1474-
info->adjusted = 1;
1468+
info->adjustable = 1;
14751469
if (clock_getres(CLOCK_REALTIME, &res) == 0)
14761470
info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
14771471
else

Python/pytime.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
4444
(void) GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement,
4545
&isTimeAdjustmentDisabled);
4646
info->resolution = timeIncrement * 1e-7;
47-
if (isTimeAdjustmentDisabled)
48-
info->adjusted = 0;
49-
else
50-
info->adjusted = 1;
47+
info->adjustable = 1;
5148
}
5249
#else
5350
/* There are three ways to get the time:
@@ -71,7 +68,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
7168
info->implementation = "gettimeofday()";
7269
info->resolution = 1e-6;
7370
info->monotonic = 0;
74-
info->adjusted = 1;
71+
info->adjustable = 1;
7572
}
7673
return;
7774
}
@@ -87,7 +84,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
8784
info->implementation = "ftime()";
8885
info->resolution = 1e-3;
8986
info->monotonic = 0;
90-
info->adjusted = 1;
87+
info->adjustable = 1;
9188
}
9289
}
9390
#else /* !HAVE_FTIME */
@@ -97,7 +94,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
9794
info->implementation = "time()";
9895
info->resolution = 1.0;
9996
info->monotonic = 0;
100-
info->adjusted = 1;
97+
info->adjustable = 1;
10198
}
10299
#endif /* !HAVE_FTIME */
103100

0 commit comments

Comments
 (0)