Commit fbaf23ff authored by Victor Stinner's avatar Victor Stinner

Backout f8409b3d6449: the PEP 410 is not accepted yet

parent 3809dbfb
...@@ -808,16 +808,13 @@ as internal buffering of data. ...@@ -808,16 +808,13 @@ as internal buffering of data.
Availability: Unix. Availability: Unix.
.. function:: fstat(fd, timestamp=None) .. function:: fstat(fd)
Return status for file descriptor *fd*, like :func:`~os.stat`. Return status for file descriptor *fd*, like :func:`~os.stat`.
Availability: Unix, Windows. Availability: Unix, Windows.
.. versionchanged:: 3.3 .. function:: fstatat(dirfd, path, flags=0)
Added the *timestamp* argument.
.. function:: fstatat(dirfd, path, flags=0, timestamp="float")
Like :func:`stat` but if *path* is relative, it is taken as relative to *dirfd*. Like :func:`stat` but if *path* is relative, it is taken as relative to *dirfd*.
*flags* is optional and may be 0 or :data:`AT_SYMLINK_NOFOLLOW`. *flags* is optional and may be 0 or :data:`AT_SYMLINK_NOFOLLOW`.
...@@ -1699,7 +1696,7 @@ Files and Directories ...@@ -1699,7 +1696,7 @@ Files and Directories
.. versionadded:: 3.3 .. versionadded:: 3.3
.. function:: lstat(path, timestamp=None) .. function:: lstat(path)
Perform the equivalent of an :c:func:`lstat` system call on the given path. Perform the equivalent of an :c:func:`lstat` system call on the given path.
Similar to :func:`~os.stat`, but does not follow symbolic links. On Similar to :func:`~os.stat`, but does not follow symbolic links. On
...@@ -1709,9 +1706,6 @@ Files and Directories ...@@ -1709,9 +1706,6 @@ Files and Directories
.. versionchanged:: 3.2 .. versionchanged:: 3.2
Added support for Windows 6.0 (Vista) symbolic links. Added support for Windows 6.0 (Vista) symbolic links.
.. versionchanged:: 3.3
The *timestamp* argument was added.
.. function:: lutimes(path[, times]) .. function:: lutimes(path[, times])
...@@ -1975,7 +1969,7 @@ Files and Directories ...@@ -1975,7 +1969,7 @@ Files and Directories
.. versionadded:: 3.3 .. versionadded:: 3.3
.. function:: stat(path, timestamp=None) .. function:: stat(path)
Perform the equivalent of a :c:func:`stat` system call on the given path. Perform the equivalent of a :c:func:`stat` system call on the given path.
(This function follows symlinks; to stat a symlink use :func:`lstat`.) (This function follows symlinks; to stat a symlink use :func:`lstat`.)
...@@ -1995,11 +1989,6 @@ Files and Directories ...@@ -1995,11 +1989,6 @@ Files and Directories
* :attr:`st_ctime` - platform dependent; time of most recent metadata change on * :attr:`st_ctime` - platform dependent; time of most recent metadata change on
Unix, or the time of creation on Windows) Unix, or the time of creation on Windows)
:attr:`st_atime`, :attr:`st_mtime` and :attr:`st_ctime` are :class:`float`
by default, or :class:`int` if :func:`os.stat_float_times` is ``False``. Set
the *timestamp* argument to get another :ref:`timestamp type
<timestamp-types>`.
On some Unix systems (such as Linux), the following attributes may also be On some Unix systems (such as Linux), the following attributes may also be
available: available:
...@@ -2055,9 +2044,6 @@ Files and Directories ...@@ -2055,9 +2044,6 @@ Files and Directories
Availability: Unix, Windows. Availability: Unix, Windows.
.. versionchanged:: 3.3
Added the *timestamp* argument.
.. function:: stat_float_times([newvalue]) .. function:: stat_float_times([newvalue])
...@@ -2083,9 +2069,6 @@ Files and Directories ...@@ -2083,9 +2069,6 @@ Files and Directories
are processed, this application should turn the feature off until the library are processed, this application should turn the feature off until the library
has been corrected. has been corrected.
.. deprecated:: 3.3
Use *timestamp* argument of stat functions instead.
.. function:: statvfs(path) .. function:: statvfs(path)
...@@ -2876,39 +2859,27 @@ written in Python, such as a mail server's external command delivery program. ...@@ -2876,39 +2859,27 @@ written in Python, such as a mail server's external command delivery program.
with :const:`P_NOWAIT` return suitable process handles. with :const:`P_NOWAIT` return suitable process handles.
.. function:: wait3(options[, timestamp=float]) .. function:: wait3([options])
Similar to :func:`waitpid`, except no process id argument is given and a Similar to :func:`waitpid`, except no process id argument is given and a
3-element tuple containing the child's process id, exit status indication, and 3-element tuple containing the child's process id, exit status indication, and
resource usage information is returned. Refer to :mod:`resource`.\ resource usage information is returned. Refer to :mod:`resource`.\
:func:`getrusage` for details on resource usage information. The option :func:`getrusage` for details on resource usage information. The option
argument is the same as that provided to :func:`waitpid` and :func:`wait4`. argument is the same as that provided to :func:`waitpid` and :func:`wait4`.
:attr:`ru_utime` and :attr:`ru_stime` attributes of the resource usage are
:class:`float` by default, set the *timestamp* argument to get another
:ref:`timestamp type <timestamp-types>`.
Availability: Unix. Availability: Unix.
.. versionchanged:: 3.3
Added the *timestamp* argument.
.. function:: wait4(pid, options[, timestamp=float]) .. function:: wait4(pid, options)
Similar to :func:`waitpid`, except a 3-element tuple, containing the child's Similar to :func:`waitpid`, except a 3-element tuple, containing the child's
process id, exit status indication, and resource usage information is returned. process id, exit status indication, and resource usage information is returned.
Refer to :mod:`resource`.\ :func:`getrusage` for details on resource usage Refer to :mod:`resource`.\ :func:`getrusage` for details on resource usage
information. The arguments to :func:`wait4` are the same as those provided to information. The arguments to :func:`wait4` are the same as those provided to
:func:`waitpid`. :func:`waitpid`.
:attr:`ru_utime` and :attr:`ru_stime` attributes of the resource usage are
:class:`float` by default, set the *timestamp* argument to get another
:ref:`timestamp type <timestamp-types>`.
Availability: Unix. Availability: Unix.
.. versionchanged:: 3.3
Added the *timestamp* argument.
.. data:: WNOHANG .. data:: WNOHANG
......
...@@ -95,14 +95,6 @@ An explanation of some terminology and conventions is in order. ...@@ -95,14 +95,6 @@ An explanation of some terminology and conventions is in order.
| local time | | | | local time | | |
+-------------------------+-------------------------+-------------------------+ +-------------------------+-------------------------+-------------------------+
.. _timestamp-types:
* Python supports the following timestamp types:
* :class:`int`
* :class:`float`
* :class:`decimal.Decimal`
The module defines the following functions and data items: The module defines the following functions and data items:
...@@ -127,7 +119,7 @@ The module defines the following functions and data items: ...@@ -127,7 +119,7 @@ The module defines the following functions and data items:
trailing newline. trailing newline.
.. function:: clock(timestamp=float) .. function:: clock()
.. index:: .. index::
single: CPU time single: CPU time
...@@ -144,27 +136,16 @@ The module defines the following functions and data items: ...@@ -144,27 +136,16 @@ The module defines the following functions and data items:
:c:func:`QueryPerformanceCounter`. The resolution is typically better than one :c:func:`QueryPerformanceCounter`. The resolution is typically better than one
microsecond. microsecond.
Return as a floating point number by default, set the *timestamp* argument
to get another :ref:`timestamp type <timestamp-types>`.
.. versionchanged:: 3.3
Added the *timestamp* argument.
.. function:: clock_getres(clk_id, timestamp=float) .. function:: clock_getres(clk_id)
Return the resolution (precision) of the specified clock *clk_id*. Return the resolution (precision) of the specified clock *clk_id*.
Return a floating point number by default, set the *timestamp* argument to
get another :ref:`timestamp type <timestamp-types>`.
.. versionadded:: 3.3 .. versionadded:: 3.3
.. function:: clock_gettime(clk_id, timestamp=float) .. function:: clock_gettime(clk_id)
Return the time of the specified clock *clk_id*. Return the time of the specified clock *clk_id*.
Return a floating point number by default, set the *timestamp* argument to
get another :ref:`timestamp type <timestamp-types>`.
.. versionadded:: 3.3 .. versionadded:: 3.3
...@@ -233,22 +214,19 @@ The module defines the following functions and data items: ...@@ -233,22 +214,19 @@ The module defines the following functions and data items:
flag is set to ``1`` when DST applies to the given time. flag is set to ``1`` when DST applies to the given time.
.. function:: mktime(t, timestamp=float) .. function:: mktime(t)
This is the inverse function of :func:`localtime`. Its argument is the This is the inverse function of :func:`localtime`. Its argument is the
:class:`struct_time` or full 9-tuple (since the dst flag is needed; use ``-1`` :class:`struct_time` or full 9-tuple (since the dst flag is needed; use ``-1``
as the dst flag if it is unknown) which expresses the time in *local* time, not as the dst flag if it is unknown) which expresses the time in *local* time, not
It returns a floating point number by default, for compatibility with UTC. It returns a floating point number, for compatibility with :func:`time`.
:func:`time`, set the *timestamp* argument to get another :ref:`timestamp
type <timestamp-types>`.
If the input value cannot be represented as a valid time, either If the input value cannot be represented as a valid time, either
:exc:`OverflowError` or :exc:`ValueError` will be raised (which depends on :exc:`OverflowError` or :exc:`ValueError` will be raised (which depends on
whether the invalid value is caught by Python or the underlying C libraries). whether the invalid value is caught by Python or the underlying C libraries).
The earliest date for which it can generate a time is platform-dependent. The earliest date for which it can generate a time is platform-dependent.
.. function:: monotonic(timestamp=float) .. function:: monotonic()
Monotonic clock. The reference point of the returned value is undefined so Monotonic clock. The reference point of the returned value is undefined so
only the difference of consecutive calls is valid. only the difference of consecutive calls is valid.
...@@ -462,20 +440,15 @@ The module defines the following functions and data items: ...@@ -462,20 +440,15 @@ The module defines the following functions and data items:
:exc:`TypeError` is raised. :exc:`TypeError` is raised.
.. function:: time(timestamp=float) .. function:: time()
Return the time expressed in seconds since the epoch in UTC. Return a Return the time as a floating point number expressed in seconds since the epoch,
floating point number by default, set the *timestamp* argument to get in UTC. Note that even though the time is always returned as a floating point
another :ref:`timestamp type <timestamp-types>`.
Note that even though the time is always returned as a floating point
number, not all systems provide time with a better precision than 1 second. number, not all systems provide time with a better precision than 1 second.
While this function normally returns non-decreasing values, it can return a While this function normally returns non-decreasing values, it can return a
lower value than a previous call if the system clock has been set back between lower value than a previous call if the system clock has been set back between
the two calls. the two calls.
.. versionchanged:: 3.3
Added the *timestamp* argument.
.. data:: timezone .. data:: timezone
...@@ -573,16 +546,13 @@ The module defines the following functions and data items: ...@@ -573,16 +546,13 @@ The module defines the following functions and data items:
('EET', 'EEST') ('EET', 'EEST')
.. function:: wallclock(timestamp=float) .. function:: wallclock()
.. index:: .. index::
single: Wallclock single: Wallclock
single: benchmarking single: benchmarking
Return the current time in fractions of a second to the system's best ability. Return the current time in fractions of a second to the system's best ability.
Return a floating point number by default, set the *timestamp* argument to
get another :ref:`timestamp type <timestamp-types>`.
Use this when the most accurate representation of wall-clock is required, i.e. Use this when the most accurate representation of wall-clock is required, i.e.
when "processor time" is inappropriate. The reference point of the returned when "processor time" is inappropriate. The reference point of the returned
value is undefined so only the difference of consecutive calls is valid. value is undefined so only the difference of consecutive calls is valid.
......
...@@ -270,42 +270,6 @@ new, more precise information:: ...@@ -270,42 +270,6 @@ new, more precise information::
'<function C.D.meth at 0x7f46b9fe31e0>' '<function C.D.meth at 0x7f46b9fe31e0>'
PEP 410: Use decimal.Decimal type for timestamps
================================================
:pep:`410` - Use decimal.Decimal type for timestamps
PEP written and implemented by Victor Stinner.
The following functions have a new optional *timestamp* argument to get a
timestamp as a :class:`decimal.Decimal` instead of :class:`int` or
:class:`float`:
* :mod:`time` module: :func:`~time.clock`, :func:`~time.clock_gettime`,
:func:`~time.clock_getres`, :func:`~time.monotonic`, :func:`~time.time` and
:func:`~time.wallclock`
* :mod:`os` module: :func:`~os.fstat`, :func:`~os.fstatat`, :func:`~os.lstat`
and :func:`~os.stat` (``st_atime``, ``st_ctime`` and ``st_mtime`` fields of
the stat structure)
:class:`decimal.Decimal` supports a resolution of a nanosecond (10^-9)
resolution, whereas :class:`float` has only a resolution of a microsecond
(10^-6) in common cases. See the list of available :ref:`timestamp types
<timestamp-types>`.
Example::
>>> import decimal, time
>>> time.time()
1328006975.681211
>>> time.time(timestamp=int)
1328006979
>>> time.time(timestamp=decimal.Decimal)
Decimal('1328006983.761119')
:func:`os.stat_float_times` has been deprecated, use *timestamp* argument of
`os.stat` instead.
Other Language Changes Other Language Changes
====================== ======================
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
#ifndef Py_PYTIME_H #ifndef Py_PYTIME_H
#define Py_PYTIME_H #define Py_PYTIME_H
#include "pyport.h" #include "pyconfig.h" /* include for defines */
#include "object.h"
/************************************************************************** /**************************************************************************
Symbols and macros to supply platform-independent interfaces to time related Symbols and macros to supply platform-independent interfaces to time related
...@@ -38,31 +37,6 @@ do { \ ...@@ -38,31 +37,6 @@ do { \
((tv_end.tv_sec - tv_start.tv_sec) + \ ((tv_end.tv_sec - tv_start.tv_sec) + \
(tv_end.tv_usec - tv_start.tv_usec) * 0.000001) (tv_end.tv_usec - tv_start.tv_usec) * 0.000001)
#if defined(HAVE_LONG_LONG)
typedef unsigned PY_LONG_LONG _PyTime_fraction_t;
#else
typedef size_t _PyTime_fraction_t;
#endif
typedef struct
{
/* timestamp = seconds + numerator / denominator */
time_t seconds;
_PyTime_fraction_t numerator;
/* denominator cannot be zero */
_PyTime_fraction_t denominator;
/* the timestamp resolution is 1/divisor */
} _PyTime_t;
/* Similar to POSIX gettimeofday. If system gettimeofday
fails or is not available, fall back to lower resolution clocks. */
PyAPI_FUNC(void) _PyTime_get(_PyTime_t *tp);
/* Convert a timestamp structure to the specified timestamp type.
Raise a ValueError if the timestamp type is unknown. */
PyAPI_FUNC(PyObject*) _PyTime_Convert(_PyTime_t *ts, PyObject *timestamp);
/* Dummy to force linking. */ /* Dummy to force linking. */
PyAPI_FUNC(void) _PyTime_Init(void); PyAPI_FUNC(void) _PyTime_Init(void);
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
# does add tests for a few functions which have been determined to be more # does add tests for a few functions which have been determined to be more
# portable than they had been thought to be. # portable than they had been thought to be.
import decimal
import os import os
import errno import errno
import unittest import unittest
...@@ -239,36 +238,6 @@ class StatAttributeTests(unittest.TestCase): ...@@ -239,36 +238,6 @@ class StatAttributeTests(unittest.TestCase):
warnings.simplefilter("ignore", DeprecationWarning) warnings.simplefilter("ignore", DeprecationWarning)
self.check_stat_attributes(fname) self.check_stat_attributes(fname)
def test_stat_timestamp(self):
# test deprecation
with warnings.catch_warnings():
warnings.simplefilter("error", DeprecationWarning)
self.assertRaises(DeprecationWarning, os.stat_float_times, False)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
old_value = os.stat_float_times()
try:
# test invalid timestamp types
self.assertRaises(ValueError, os.stat, self.fname,
timestamp="abc")
self.assertRaises(ValueError, os.stat, self.fname,
timestamp=decimal.Context)
for float_times in (False, True):
os.stat_float_times(float_times)
t = os.stat(self.fname).st_mtime
if float_times:
self.assertIsInstance(t, float)
else:
self.assertIsInstance(t, int)
for type in (int, float, decimal.Decimal):
t = os.stat(self.fname, timestamp=type).st_mtime
self.assertIsInstance(t, type)
finally:
os.stat_float_times(old_value)
def test_statvfs_attributes(self): def test_statvfs_attributes(self):
if not hasattr(os, "statvfs"): if not hasattr(os, "statvfs"):
return return
......
import locale
import platform
import sys
import sysconfig
from test import support from test import support
import time import time
import unittest import unittest
import locale
import sysconfig
import sys
import platform
# Max year is only limited by the size of C int. # Max year is only limited by the size of C int.
SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4 SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4
...@@ -345,31 +345,6 @@ class TimeTestCase(unittest.TestCase): ...@@ -345,31 +345,6 @@ class TimeTestCase(unittest.TestCase):
self.assertGreater(t2, t1) self.assertGreater(t2, t1)
self.assertAlmostEqual(dt, 0.1, delta=0.2) self.assertAlmostEqual(dt, 0.1, delta=0.2)
def test_timestamp(self):
import decimal
calls = [
(time.time,),
(time.mktime, time.localtime()),
]
if hasattr(time, 'monotonic'):
calls.append((time.monotonic,))
if hasattr(time, 'wallclock'):
calls.append((time.wallclock,))
if hasattr(time, 'CLOCK_REALTIME'):
if hasattr(time, 'clock_gettime'):
calls.append((time.clock_gettime, time.CLOCK_REALTIME))
if hasattr(time, 'clock_getres'):
calls.append((time.clock_getres, time.CLOCK_REALTIME))
for call in calls:
func, *args = call
# test invalid timestamp
for invalid in ("int", decimal.Context):
self.assertRaises(ValueError, func, *args, timestamp=invalid)
for type in (int, float, decimal.Decimal):
self.assertIsInstance(func(*args, timestamp=type), type)
def test_wallclock(self): def test_wallclock(self):
t1 = time.wallclock() t1 = time.wallclock()
t2 = time.wallclock() t2 = time.wallclock()
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment