classification
Title: os.utime() mishandles some arguments
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, corona10, larry, roger.serwy, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2012-07-17 21:02 by Arfrever, last changed 2019-09-09 09:01 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
issue15382.patch roger.serwy, 2012-07-17 23:08 review
issue15382_rev1.patch roger.serwy, 2012-07-17 23:19 review
Messages (8)
msg165730 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2012-07-17 21:02
Contrarily to documentation:

1. os.utime() accepts a tuple with floats passed by ns argument:
>>> os.utime(file, ns=(0.5, 0.5))
>>>

2. os.utime() does not accept explicit ns=None:
>>> os.utime(file, times=None)
>>> os.utime(file, ns=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: utime: 'ns' must be a tuple of two ints
>>>

3. os.utime() does not accept both times and ns when only times is a tuple:
>>> os.utime(file, times=None, ns=(0, 0))
>>> os.utime(file, times=(0, 0), ns=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: utime: you may specify either 'times' or 'ns' but not both
>>>
msg165733 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-07-17 23:08
Attached is a preliminary patch to check ns != Py_None.
msg165734 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-07-17 23:10
@serwy: can you please write a test for your patch?
msg165736 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-07-17 23:19
_rev1 has a basic test. Is it sufficient?
msg351279 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2019-09-07 04:11
@vstinner
This issue is not solved yet.
Can I finalize this issue?
msg351298 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-09-07 09:45
The documentation issue was fixed in issue23738. The documentation no longer claims that ns can be None. If specified it must be a tuple of floats.
msg351365 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-09 08:54
> The documentation issue was fixed in issue23738. The documentation no longer claims that ns can be None. If specified it must be a tuple of floats.

tuple of integers, not tuple a floats.

Python 3.9 documentation says: "If ns is specified, it must be a 2-tuple of the form (atime_ns, mtime_ns) where each member is an int expressing nanoseconds." which is correct.

Python 3.9 now emits a DeprecationWarning when passing floats:

vstinner@apu$ ./python
Python 3.9.0a0 (heads/pr/15701-dirty:a0f335c74c, Sep  6 2019, 17:38:14) 
>>> import os
>>> os.utime("x", ns=(1, 1))
>>> os.utime("x", ns=(0.1, 1))
<stdin>:1: DeprecationWarning: an integer is required (got type float).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
msg351366 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-09 09:01
By the way, error messages are now also correct:

>>> os.utime("x", ns=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: utime: 'ns' must be a tuple of two ints

>>> os.utime("x", times=(0, 0), ns=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: utime: you may specify either 'times' or 'ns' but not both
History
Date User Action Args
2019-09-09 09:01:47vstinnersetmessages: + msg351366
2019-09-09 08:54:43vstinnersetmessages: + msg351365
2019-09-07 09:45:24serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg351298

resolution: out of date
stage: resolved
2019-09-07 04:11:20corona10setnosy: + corona10
messages: + msg351279
2012-07-17 23:19:44roger.serwysetfiles: + issue15382_rev1.patch

messages: + msg165736
2012-07-17 23:10:39vstinnersetmessages: + msg165734
2012-07-17 23:08:24roger.serwysetfiles: + issue15382.patch

type: behavior
components: + Library (Lib)

keywords: + patch
nosy: + roger.serwy
messages: + msg165733
2012-07-17 21:02:38Arfrevercreate