Skip to content

Commit be7d76f

Browse files
jbosboomvstinner
andcommitted
Apply suggestions from code review
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 30d790f commit be7d76f

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

Lib/test/test_os.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,9 @@ def test_large_time(self):
10701070
-9223372037, -9223372036, 9223372035, 9223372036,
10711071
)
10721072
for large in times:
1073-
os.utime(self.fname, (large, large))
1074-
self.assertEqual(os.stat(self.fname).st_mtime, large)
1073+
with self.subTest(large=large):
1074+
os.utime(self.fname, (large, large))
1075+
self.assertEqual(os.stat(self.fname).st_mtime, large)
10751076

10761077
def test_utime_invalid_arguments(self):
10771078
# seconds and nanoseconds parameters are mutually exclusive

Modules/posixmodule.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,20 +2588,20 @@ static int
25882588
fill_time(PyObject *module, PyObject *v, int s_index, int f_index, int ns_index, time_t sec, unsigned long nsec)
25892589
{
25902590
assert(!PyErr_Occurred());
2591-
#define S_TO_NS (1000000000LL)
2592-
assert(nsec < S_TO_NS);
2591+
#define SEC_TO_NS (1000000000LL)
2592+
assert(nsec < SEC_TO_NS);
25932593

25942594
if (s_index >= 0) {
25952595
PyObject *s = _PyLong_FromTime_t(sec);
2596-
if (!s) {
2596+
if (s == NULL) {
25972597
return -1;
25982598
}
25992599
PyStructSequence_SET_ITEM(v, s_index, s);
26002600
}
26012601

26022602
if (f_index >= 0) {
2603-
PyObject *float_s = PyFloat_FromDouble(sec + 1e-9 * nsec);
2604-
if (!float_s) {
2603+
PyObject *float_s = PyFloat_FromDouble((double)sec + 1e-9 * nsec);
2604+
if (float_s == NULL) {
26052605
return -1;
26062606
}
26072607
PyStructSequence_SET_ITEM(v, f_index, float_s);
@@ -2610,9 +2610,9 @@ fill_time(PyObject *module, PyObject *v, int s_index, int f_index, int ns_index,
26102610
int res = -1;
26112611
if (ns_index >= 0) {
26122612
/* 1677-09-21 00:12:44 to 2262-04-11 23:47:15 UTC inclusive */
2613-
if ((LLONG_MIN / S_TO_NS) <= sec && sec <= (LLONG_MAX / S_TO_NS - 1)) {
2614-
PyObject *ns_total = PyLong_FromLongLong(sec * S_TO_NS + nsec);
2615-
if (!ns_total) {
2613+
if ((LLONG_MIN/SEC_TO_NS) <= sec && sec <= (LLONG_MAX/SEC_TO_NS - 1)) {
2614+
PyObject *ns_total = PyLong_FromLongLong(sec * SEC_TO_NS + nsec);
2615+
if (ns_total == NULL) {
26162616
return -1;
26172617
}
26182618
PyStructSequence_SET_ITEM(v, ns_index, ns_total);
@@ -2624,17 +2624,17 @@ fill_time(PyObject *module, PyObject *v, int s_index, int f_index, int ns_index,
26242624
PyObject *ns_total = NULL;
26252625
PyObject *s = _PyLong_FromTime_t(sec);
26262626
PyObject *ns_fractional = PyLong_FromUnsignedLong(nsec);
2627-
if (!(s && ns_fractional)) {
2627+
if (s == NULL || ns_fractional == NULL) {
26282628
goto exit;
26292629
}
26302630

26312631
s_in_ns = PyNumber_Multiply(s, get_posix_state(module)->billion);
2632-
if (!s_in_ns) {
2632+
if (s_in_ns == NULL) {
26332633
goto exit;
26342634
}
26352635

26362636
ns_total = PyNumber_Add(s_in_ns, ns_fractional);
2637-
if (!ns_total) {
2637+
if (ns_total == NULL) {
26382638
goto exit;
26392639
}
26402640
PyStructSequence_SET_ITEM(v, ns_index, ns_total);
@@ -2649,7 +2649,7 @@ fill_time(PyObject *module, PyObject *v, int s_index, int f_index, int ns_index,
26492649
}
26502650

26512651
return res;
2652-
#undef S_TO_NS
2652+
#undef SEC_TO_NS
26532653
}
26542654

26552655
#ifdef MS_WINDOWS

0 commit comments

Comments
 (0)