Skip to content

Commit d150e4a

Browse files
authored
Highlight datetime.timedelta.seconds vs .total_seconds() in docs. (GH-124811)
Thanks to the reviewers for suggesting the use of a "caution" section instead of "warning" or "note".
1 parent 5e0abb4 commit d150e4a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Doc/library/datetime.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ Instance attributes (read-only):
295295

296296
Between 0 and 86,399 inclusive.
297297

298+
.. caution::
299+
300+
It is a somewhat common bug for code to unintentionally use this attribute
301+
when it is actually intended to get a :meth:`~timedelta.total_seconds`
302+
value instead:
303+
304+
.. doctest::
305+
306+
>>> from datetime import timedelta
307+
>>> duration = timedelta(seconds=11235813)
308+
>>> duration.days, duration.seconds
309+
(130, 3813)
310+
>>> duration.total_seconds()
311+
11235813.0
298312

299313
.. attribute:: timedelta.microseconds
300314

@@ -351,7 +365,7 @@ Supported operations:
351365
| | same value. (2) |
352366
+--------------------------------+-----------------------------------------------+
353367
| ``-t1`` | Equivalent to ``timedelta(-t1.days, |
354-
| | -t1.seconds*, -t1.microseconds)``, |
368+
| | -t1.seconds, -t1.microseconds)``, |
355369
| | and to ``t1 * -1``. (1)(4) |
356370
+--------------------------------+-----------------------------------------------+
357371
| ``abs(t)`` | Equivalent to ``+t`` when ``t.days >= 0``, |

0 commit comments

Comments
 (0)