[Python-checkins] bpo-31327: Update time documentation to reflect possible errors (GH-31460) (GH-31827)

ambv webhook-mailer at python.org
Wed Mar 16 06:13:00 EDT 2022


https://github.com/python/cpython/commit/4d8e08b21ce5d2cc08da82cf9f3ca50d9617cbdc
commit: 4d8e08b21ce5d2cc08da82cf9f3ca50d9617cbdc
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2022-03-16T11:12:50+01:00
summary:

bpo-31327: Update time documentation to reflect possible errors (GH-31460) (GH-31827)

As per the comments, this mirrors the [datetime documentation](https://docs.python.org/3/library/datetime.htmlGH-datetime.datetime.fromtimestamp).

```
>>> import time
>>> time.localtime(999999999999999999999)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: timestamp out of range for platform time_t
>>> time.localtime(-3600)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument
```
(cherry picked from commit c83fc9c02c9846ec3a2d0123999c98e02f00b3f5)

Co-authored-by: slateny <46876382+slateny at users.noreply.github.com>

files:
M Doc/library/time.rst

diff --git a/Doc/library/time.rst b/Doc/library/time.rst
index e8bb9ccb8e77c..9cdef1adec975 100644
--- a/Doc/library/time.rst
+++ b/Doc/library/time.rst
@@ -253,6 +253,12 @@ Functions
    :const:`None`, the current time as returned by :func:`.time` is used.  The dst
    flag is set to ``1`` when DST applies to the given time.
 
+   :func:`localtime` may raise :exc:`OverflowError`, if the timestamp is
+   outside the range of values supported by the platform C :c:func:`localtime`
+   or :c:func:`gmtime` functions, and :exc:`OSError` on :c:func:`localtime` or
+   :c:func:`gmtime` failure. It's common for this to be restricted to years
+   between 1970 and 2038.
+
 
 .. function:: mktime(t)
 



More information about the Python-checkins mailing list