Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions Doc/library/os.path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
29 changes: 0 additions & 29 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be changed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I tried to remove the backward compatibility layer: I modified stat_result[ST_MTIME] to return float rather than int. Problem: it broke test_logging, the code deciding if a log file should be rotated or not.

While I'm not strongly opposed to modify stat_result[ST_MTIME], I prefer to do it in a separated PR. Moreover, we need maybe to emit a DeprecationWarning, or at least deprecate the feature in the doc, before changing the type, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it should be done in a separate issue. It needs a special discussion. And maybe this can't be changed.

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
Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 0 additions & 17 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@
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)

Expand Down Expand Up @@ -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'):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore_deprecation_warnings no longer used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
48 changes: 4 additions & 44 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Tools/c-globals/ignored-globals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down