]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Highlight `datetime.timedelta.seconds` vs `.total_seconds()` in docs. (GH-124811)
authorGregory P. Smith <greg@krypto.org>
Tue, 1 Oct 2024 18:10:13 +0000 (11:10 -0700)
committerGitHub <noreply@github.com>
Tue, 1 Oct 2024 18:10:13 +0000 (18:10 +0000)
Thanks to the reviewers for suggesting the use of a "caution" section instead of "warning" or "note".

Doc/library/datetime.rst

index 59e2dbd6847538f6f3909b46c020a0a3720500e9..64510a77c67c118233064b02d5f4c8a0bb278243 100644 (file)
@@ -295,6 +295,20 @@ Instance attributes (read-only):
 
    Between 0 and 86,399 inclusive.
 
+   .. caution::
+
+      It is a somewhat common bug for code to unintentionally use this attribute
+      when it is actually intended to get a :meth:`~timedelta.total_seconds`
+      value instead:
+
+      .. doctest::
+
+         >>> from datetime import timedelta
+         >>> duration = timedelta(seconds=11235813)
+         >>> duration.days, duration.seconds
+         (130, 3813)
+         >>> duration.total_seconds()
+         11235813.0
 
 .. attribute:: timedelta.microseconds
 
@@ -351,7 +365,7 @@ Supported operations:
 |                                | same value. (2)                               |
 +--------------------------------+-----------------------------------------------+
 | ``-t1``                        | Equivalent to ``timedelta(-t1.days,           |
-|                                | -t1.seconds*, -t1.microseconds)``,            |
+|                                | -t1.seconds, -t1.microseconds)``,             |
 |                                | and to ``t1 * -1``. (1)(4)                    |
 +--------------------------------+-----------------------------------------------+
 | ``abs(t)``                     | Equivalent to ``+t`` when ``t.days >= 0``,    |