[Python-checkins] cpython: Fix 13327. Remove explicit None arguments from futimes, futimens, futimesat,

brian.curtin python-checkins at python.org
Mon Nov 7 21:20:10 CET 2011


http://hg.python.org/cpython/rev/045e8757f10d
changeset:   73437:045e8757f10d
user:        Brian Curtin <brian at python.org>
date:        Mon Nov 07 14:18:54 2011 -0600
summary:
  Fix 13327. Remove explicit None arguments from futimes, futimens, futimesat,
and lutimes.

files:
  Doc/library/os.rst     |  16 +++++--------
  Lib/test/test_posix.py |   4 +++
  Modules/posixmodule.c  |  35 ++++++++++++++---------------
  3 files changed, 27 insertions(+), 28 deletions(-)


diff --git a/Doc/library/os.rst b/Doc/library/os.rst
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -872,8 +872,7 @@
    .. versionadded:: 3.3
 
 
-.. function:: futimesat(dirfd, path, (atime, mtime))
-              futimesat(dirfd, path, None)
+.. function:: futimesat(dirfd, path[, (atime, mtime)])
 
    Like :func:`utime` but if *path* is relative, it is taken as relative to *dirfd*.
    If *path* is relative and *dirfd* is the special value :data:`AT_FDCWD`, then *path*
@@ -884,12 +883,11 @@
    .. versionadded:: 3.3
 
 
-.. function:: futimens(fd, (atime_sec, atime_nsec), (mtime_sec, mtime_nsec))
-              futimens(fd, None, None)
+.. function:: futimens(fd[, (atime_sec, atime_nsec), (mtime_sec, mtime_nsec)])
 
    Updates the timestamps of a file specified by the file descriptor *fd*, with
    nanosecond precision.
-   The second form sets *atime* and *mtime* to the current time.
+   If no second argument is given, set *atime* and *mtime* to the current time.
    If *atime_nsec* or *mtime_nsec* is specified as :data:`UTIME_NOW`, the corresponding
    timestamp is updated to the current time.
    If *atime_nsec* or *mtime_nsec* is specified as :data:`UTIME_OMIT`, the corresponding
@@ -911,11 +909,10 @@
    .. versionadded:: 3.3
 
 
-.. function:: futimes(fd, (atime, mtime))
-              futimes(fd, None)
+.. function:: futimes(fd[, (atime, mtime)])
 
    Set the access and modified time of the file specified by the file
-   descriptor *fd* to the given values. If the second form is used, set the
+   descriptor *fd* to the given values. If no second argument is used, set the
    access and modified times to the current time.
 
    Availability: Unix.
@@ -1702,8 +1699,7 @@
       Added support for Windows 6.0 (Vista) symbolic links.
 
 
-.. function:: lutimes(path, (atime, mtime))
-              lutimes(path, None)
+.. function:: lutimes(path[, (atime, mtime)])
 
    Like :func:`utime`, but if *path* is a symbolic link, it is not
    dereferenced.
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -235,6 +235,7 @@
         fd = os.open(support.TESTFN, os.O_RDONLY)
         try:
             posix.futimes(fd, None)
+            posix.futimes(fd)
             self.assertRaises(TypeError, posix.futimes, fd, (None, None))
             self.assertRaises(TypeError, posix.futimes, fd, (now, None))
             self.assertRaises(TypeError, posix.futimes, fd, (None, now))
@@ -252,6 +253,7 @@
         self.assertRaises(TypeError, posix.lutimes, support.TESTFN, (None, now))
         posix.lutimes(support.TESTFN, (int(now), int(now)))
         posix.lutimes(support.TESTFN, (now, now))
+        posix.lutimes(support.TESTFN)
 
     @unittest.skipUnless(hasattr(posix, 'futimens'), "test needs posix.futimens()")
     def test_futimens(self):
@@ -263,6 +265,7 @@
             self.assertRaises(TypeError, posix.futimens, fd, None, (now, 0))
             posix.futimens(fd, (int(now), int((now - int(now)) * 1e9)),
                     (int(now), int((now - int(now)) * 1e9)))
+            posix.futimens(fd)
         finally:
             os.close(fd)
 
@@ -691,6 +694,7 @@
         try:
             now = time.time()
             posix.futimesat(f, support.TESTFN, None)
+            posix.futimesat(f, support.TESTFN)
             self.assertRaises(TypeError, posix.futimesat, f, support.TESTFN, (None, None))
             self.assertRaises(TypeError, posix.futimesat, f, support.TESTFN, (now, None))
             self.assertRaises(TypeError, posix.futimesat, f, support.TESTFN, (None, now))
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -3534,10 +3534,10 @@
 }
 
 PyDoc_STRVAR(posix_utime__doc__,
-"utime(path, (atime, mtime))\n\
-utime(path, None)\n\n\
-Set the access and modified time of the file to the given values.  If the\n\
-second form is used, set the access and modified times to the current time.");
+"utime(path[, (atime, mtime)])\n\
+Set the access and modified time of the file to the given values.\n\
+If no second argument is used, set the access and modified times to\n\
+the current time.");
 
 static PyObject *
 posix_utime(PyObject *self, PyObject *args)
@@ -3706,21 +3706,20 @@
 
 #ifdef HAVE_FUTIMES
 PyDoc_STRVAR(posix_futimes__doc__,
-"futimes(fd, (atime, mtime))\n\
-futimes(fd, None)\n\n\
+"futimes(fd[, (atime, mtime)])\n\
 Set the access and modified time of the file specified by the file\n\
-descriptor fd to the given values. If the second form is used, set the\n\
+descriptor fd to the given values. If no second argument is used, set the\n\
 access and modified times to the current time.");
 
 static PyObject *
 posix_futimes(PyObject *self, PyObject *args)
 {
     int res, fd;
-    PyObject* arg;
+    PyObject* arg = Py_None;
     time_t atime, mtime;
     long ausec, musec;
 
-    if (!PyArg_ParseTuple(args, "iO:futimes", &fd, &arg))
+    if (!PyArg_ParseTuple(args, "i|O:futimes", &fd, &arg))
         return NULL;
 
     if (arg == Py_None) {
@@ -3771,20 +3770,20 @@
 
 #ifdef HAVE_LUTIMES
 PyDoc_STRVAR(posix_lutimes__doc__,
-"lutimes(path, (atime, mtime))\n\
-lutimes(path, None)\n\n\
+"lutimes(path[, (atime, mtime)])\n\
 Like utime(), but if path is a symbolic link, it is not dereferenced.");
 
 static PyObject *
 posix_lutimes(PyObject *self, PyObject *args)
 {
-    PyObject *opath, *arg;
+    PyObject *opath;
+    PyObject *arg = Py_None;
     const char *path;
     int res;
     time_t atime, mtime;
     long ausec, musec;
 
-    if (!PyArg_ParseTuple(args, "O&O:lutimes",
+    if (!PyArg_ParseTuple(args, "O&|O:lutimes",
             PyUnicode_FSConverter, &opath, &arg))
         return NULL;
     path = PyBytes_AsString(opath);
@@ -3840,11 +3839,10 @@
 
 #ifdef HAVE_FUTIMENS
 PyDoc_STRVAR(posix_futimens__doc__,
-"futimens(fd, (atime_sec, atime_nsec), (mtime_sec, mtime_nsec))\n\
-futimens(fd, None, None)\n\n\
+"futimens(fd[, (atime_sec, atime_nsec), (mtime_sec, mtime_nsec)])\n\
 Updates the timestamps of a file specified by the file descriptor fd, with\n\
 nanosecond precision.\n\
-The second form sets atime and mtime to the current time.\n\
+If no second argument is given, set atime and mtime to the current time.\n\
 If *_nsec is specified as UTIME_NOW, the timestamp is updated to the\n\
 current time.\n\
 If *_nsec is specified as UTIME_OMIT, the timestamp is not updated.");
@@ -3853,10 +3851,11 @@
 posix_futimens(PyObject *self, PyObject *args)
 {
     int res, fd;
-    PyObject *atime, *mtime;
+    PyObject *atime = Py_None;
+    PyObject *mtime = Py_None;
     struct timespec buf[2];
 
-    if (!PyArg_ParseTuple(args, "iOO:futimens",
+    if (!PyArg_ParseTuple(args, "i|OO:futimens",
             &fd, &atime, &mtime))
         return NULL;
     if (atime == Py_None && mtime == Py_None) {

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list