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

This commit is contained in:
Victor Stinner 2017-10-24 02:02:00 -07:00 committed by GitHub
parent 87d332dcdb
commit 01b5aab7bf
7 changed files with 13 additions and 99 deletions

View File

@ -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`.

View File

@ -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

View File

@ -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.

View File

@ -81,12 +81,6 @@ else:
HAVE_WHEEL_GROUP = sys.platform.startswith('freebsd') and os.getgid() == 0
@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 @@ class UtimeTests(unittest.TestCase):
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

View File

@ -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.

View File

@ -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

View File

@ -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