[Python-checkins] bpo-31827: Remove os.stat_float_times() (GH-4061)

Victor Stinner webhook-mailer at python.org
Tue Oct 24 05:02:03 EDT 2017


https://github.com/python/cpython/commit/01b5aab7bfb11ee5476ef52d24495598cbe7c99a
commit: 01b5aab7bfb11ee5476ef52d24495598cbe7c99a
branch: master
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-10-24T02:02:00-07:00
summary:

bpo-31827: Remove os.stat_float_times() (GH-4061)

files:
A Misc/NEWS.d/next/Library/2017-10-20-16-12-01.bpo-31827.7R8s8s.rst
M Doc/library/os.path.rst
M Doc/library/os.rst
M Doc/whatsnew/3.7.rst
M Lib/test/test_os.py
M Modules/posixmodule.c
M Tools/c-globals/ignored-globals.txt

diff --git a/Doc/library/os.path.rst b/Doc/library/os.path.rst
index 38a93315770..06d4ecedd86 100644
--- a/Doc/library/os.path.rst
+++ b/Doc/library/os.path.rst
@@ -192,23 +192,17 @@ the :mod:`glob` module.)
 
 .. function:: getatime(path)
 
-   Return the time of last access of *path*.  The return value is a number giving
+   Return the time of last access of *path*.  The return value is a floating point number giving
    the number of seconds since the epoch (see the  :mod:`time` module).  Raise
    :exc:`OSError` if the file does not exist or is inaccessible.
 
-   If :func:`os.stat_float_times` returns ``True``, the result is a floating point
-   number.
-
 
 .. function:: getmtime(path)
 
-   Return the time of last modification of *path*.  The return value is a number
+   Return the time of last modification of *path*.  The return value is a floating point number
    giving the number of seconds since the epoch (see the  :mod:`time` module).
    Raise :exc:`OSError` if the file does not exist or is inaccessible.
 
-   If :func:`os.stat_float_times` returns ``True``, the result is a floating point
-   number.
-
    .. versionchanged:: 3.6
       Accepts a :term:`path-like object`.
 
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 86add0cb8e1..95c81137230 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -2335,8 +2335,6 @@ features:
       * the time of creation on Windows, expressed in nanoseconds as an
         integer.
 
-   See also the :func:`stat_float_times` function.
-
    .. note::
 
       The exact meaning and resolution of the :attr:`st_atime`,
@@ -2431,33 +2429,6 @@ features:
       Added the :attr:`st_file_attributes` member on Windows.
 
 
-.. function:: stat_float_times([newvalue])
-
-   Determine whether :class:`stat_result` represents time stamps as float objects.
-   If *newvalue* is ``True``, future calls to :func:`~os.stat` return floats, if it is
-   ``False``, future calls return ints. If *newvalue* is omitted, return the
-   current setting.
-
-   For compatibility with older Python versions, accessing :class:`stat_result` as
-   a tuple always returns integers.
-
-   Python now returns float values by default. Applications which do not work
-   correctly with floating point time stamps can use this function to restore the
-   old behaviour.
-
-   The resolution of the timestamps (that is the smallest possible fraction)
-   depends on the system. Some systems only support second resolution; on these
-   systems, the fraction will always be zero.
-
-   It is recommended that this setting is only changed at program startup time in
-   the *__main__* module; libraries should never change this setting. If an
-   application uses a library that works incorrectly if floating point time stamps
-   are processed, this application should turn the feature off until the library
-   has been corrected.
-
-   .. deprecated:: 3.3
-
-
 .. function:: statvfs(path)
 
    Perform a :c:func:`statvfs` system call on the given path.  The return value is
diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst
index 11b99e2d1c4..5bff3a4181a 100644
--- a/Doc/whatsnew/3.7.rst
+++ b/Doc/whatsnew/3.7.rst
@@ -507,6 +507,10 @@ Removed
 API and Feature Removals
 ------------------------
 
+* The ``os.stat_float_times()`` function has been removed. It was introduced in
+  Python 2.3 for backward compatibility with Python 2.2, and was deprecated
+  since Python 3.1.
+
 * Unknown escapes consisting of ``'\'`` and an ASCII letter in replacement
   templates for :func:`re.sub` were deprecated in Python 3.5, and will now
   cause an error.
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index d7d08cece3c..18edbcda652 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -81,12 +81,6 @@
 HAVE_WHEEL_GROUP = sys.platform.startswith('freebsd') and os.getgid() == 0
 
 
- at contextlib.contextmanager
-def ignore_deprecation_warnings(msg_regex, quiet=False):
-    with support.check_warnings((msg_regex, DeprecationWarning), quiet=quiet):
-        yield
-
-
 def requires_os_func(name):
     return unittest.skipUnless(hasattr(os, name), 'requires os.%s' % name)
 
@@ -488,17 +482,6 @@ def setUp(self):
         os.mkdir(self.dirname)
         create_file(self.fname)
 
-        def restore_float_times(state):
-            with ignore_deprecation_warnings('stat_float_times'):
-                os.stat_float_times(state)
-
-        # ensure that st_atime and st_mtime are float
-        with ignore_deprecation_warnings('stat_float_times'):
-            old_float_times = os.stat_float_times(-1)
-            self.addCleanup(restore_float_times, old_float_times)
-
-            os.stat_float_times(True)
-
     def support_subsecond(self, filename):
         # Heuristic to check if the filesystem supports timestamp with
         # subsecond resolution: check if float and int timestamps are different
diff --git a/Misc/NEWS.d/next/Library/2017-10-20-16-12-01.bpo-31827.7R8s8s.rst b/Misc/NEWS.d/next/Library/2017-10-20-16-12-01.bpo-31827.7R8s8s.rst
new file mode 100644
index 00000000000..ae007234d33
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-10-20-16-12-01.bpo-31827.7R8s8s.rst
@@ -0,0 +1,3 @@
+Remove the os.stat_float_times() function. It was introduced in Python 2.3
+for backward compatibility with Python 2.2, and was deprecated since Python
+3.1.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 639e45021f2..c7d8b00e6f9 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1934,36 +1934,6 @@ statresult_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 }
 
 
-
-/* If true, st_?time is float. */
-static int _stat_float_times = 1;
-
-PyDoc_STRVAR(stat_float_times__doc__,
-"stat_float_times([newval]) -> oldval\n\n\
-Determine whether os.[lf]stat represents time stamps as float objects.\n\
-\n\
-If value is True, future calls to stat() return floats; if it is False,\n\
-future calls return ints.\n\
-If value is omitted, return the current setting.\n");
-
-/* AC 3.5: the public default value should be None, not ready for that yet */
-static PyObject*
-stat_float_times(PyObject* self, PyObject *args)
-{
-    int newval = -1;
-    if (!PyArg_ParseTuple(args, "|i:stat_float_times", &newval))
-        return NULL;
-    if (PyErr_WarnEx(PyExc_DeprecationWarning,
-                     "stat_float_times() is deprecated",
-                     1))
-        return NULL;
-    if (newval == -1)
-        /* Return old value */
-        return PyBool_FromLong(_stat_float_times);
-    _stat_float_times = newval;
-    Py_RETURN_NONE;
-}
-
 static PyObject *billion = NULL;
 
 static void
@@ -1986,14 +1956,9 @@ fill_time(PyObject *v, int index, time_t sec, unsigned long nsec)
     if (!ns_total)
         goto exit;
 
-    if (_stat_float_times) {
-        float_s = PyFloat_FromDouble(sec + 1e-9*nsec);
-        if (!float_s)
-            goto exit;
-    }
-    else {
-        float_s = s;
-        Py_INCREF(float_s);
+    float_s = PyFloat_FromDouble(sec + 1e-9*nsec);
+    if (!float_s) {
+        goto exit;
     }
 
     PyStructSequence_SET_ITEM(v, index, s);
@@ -2084,11 +2049,7 @@ _pystat_fromstructstat(STRUCT_STAT *st)
 #else
       bnsec = 0;
 #endif
-      if (_stat_float_times) {
-        val = PyFloat_FromDouble(bsec + 1e-9*bnsec);
-      } else {
-        val = PyLong_FromLong((long)bsec);
-      }
+      val = PyFloat_FromDouble(bsec + 1e-9*bnsec);
       PyStructSequence_SET_ITEM(v, ST_BIRTHTIME_IDX,
                                 val);
     }
@@ -12452,7 +12413,6 @@ static PyMethodDef posix_methods[] = {
     OS_RENAME_METHODDEF
     OS_REPLACE_METHODDEF
     OS_RMDIR_METHODDEF
-    {"stat_float_times", stat_float_times, METH_VARARGS, stat_float_times__doc__},
     OS_SYMLINK_METHODDEF
     OS_SYSTEM_METHODDEF
     OS_UMASK_METHODDEF
diff --git a/Tools/c-globals/ignored-globals.txt b/Tools/c-globals/ignored-globals.txt
index 4fafba6eefa..7b5add865c1 100644
--- a/Tools/c-globals/ignored-globals.txt
+++ b/Tools/c-globals/ignored-globals.txt
@@ -122,7 +122,6 @@ user_signals
 posix_constants_confstr
 posix_constants_pathconf
 posix_constants_sysconf
-_stat_float_times  # deprecated, __main__-only
 structseq_new
 ticks_per_second
 



More information about the Python-checkins mailing list