Skip to content

Commit 809aa9a

Browse files
uatachserhiy-storchakaJelleZijlstraerlend-aasland
authored
gh-85453: Adapt datetime.rst to devguide recommendations for code snippets and variables (#118068)
Also remove formatting from numeric literals. Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 5865fa5 commit 809aa9a

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

Diff for: Doc/library/datetime.rst

+45-45
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ The :mod:`!datetime` module exports the following constants:
8585
.. data:: MINYEAR
8686

8787
The smallest year number allowed in a :class:`date` or :class:`.datetime` object.
88-
:const:`MINYEAR` is ``1``.
88+
:const:`MINYEAR` is 1.
8989

9090

9191
.. data:: MAXYEAR
@@ -207,7 +207,7 @@ A :class:`timedelta` object represents a duration, the difference between two
207207

208208
.. class:: timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
209209

210-
All arguments are optional and default to ``0``. Arguments may be integers
210+
All arguments are optional and default to 0. Arguments may be integers
211211
or floats, and may be positive or negative.
212212

213213
Only *days*, *seconds* and *microseconds* are stored internally.
@@ -280,7 +280,7 @@ Class attributes:
280280
The smallest possible difference between non-equal :class:`timedelta` objects,
281281
``timedelta(microseconds=1)``.
282282

283-
Note that, because of normalization, ``timedelta.max`` > ``-timedelta.min``.
283+
Note that, because of normalization, ``timedelta.max`` is greater than ``-timedelta.min``.
284284
``-timedelta.max`` is not representable as a :class:`timedelta` object.
285285

286286
Instance attributes (read-only):
@@ -302,26 +302,27 @@ Supported operations:
302302
+--------------------------------+-----------------------------------------------+
303303
| Operation | Result |
304304
+================================+===============================================+
305-
| ``t1 = t2 + t3`` | Sum of *t2* and *t3*. Afterwards *t1*-*t2* == |
306-
| | *t3* and *t1*-*t3* == *t2* are true. (1) |
305+
| ``t1 = t2 + t3`` | Sum of ``t2`` and ``t3``. |
306+
| | Afterwards ``t1 - t2 == t3`` and |
307+
| | ``t1 - t3 == t2`` are true. (1) |
307308
+--------------------------------+-----------------------------------------------+
308-
| ``t1 = t2 - t3`` | Difference of *t2* and *t3*. Afterwards *t1* |
309-
| | == *t2* - *t3* and *t2* == *t1* + *t3* are |
309+
| ``t1 = t2 - t3`` | Difference of ``t2`` and ``t3``. Afterwards |
310+
| | ``t1 == t2 - t3`` and ``t2 == t1 + t3`` are |
310311
| | true. (1)(6) |
311312
+--------------------------------+-----------------------------------------------+
312313
| ``t1 = t2 * i or t1 = i * t2`` | Delta multiplied by an integer. |
313-
| | Afterwards *t1* // i == *t2* is true, |
314+
| | Afterwards ``t1 // i == t2`` is true, |
314315
| | provided ``i != 0``. |
315316
+--------------------------------+-----------------------------------------------+
316-
| | In general, *t1* \* i == *t1* \* (i-1) + *t1* |
317+
| | In general, ``t1 * i == t1 * (i-1) + t1`` |
317318
| | is true. (1) |
318319
+--------------------------------+-----------------------------------------------+
319320
| ``t1 = t2 * f or t1 = f * t2`` | Delta multiplied by a float. The result is |
320321
| | rounded to the nearest multiple of |
321322
| | timedelta.resolution using round-half-to-even.|
322323
+--------------------------------+-----------------------------------------------+
323-
| ``f = t2 / t3`` | Division (3) of overall duration *t2* by |
324-
| | interval unit *t3*. Returns a :class:`float` |
324+
| ``f = t2 / t3`` | Division (3) of overall duration ``t2`` by |
325+
| | interval unit ``t3``. Returns a :class:`float`|
325326
| | object. |
326327
+--------------------------------+-----------------------------------------------+
327328
| ``t1 = t2 / f or t1 = t2 / i`` | Delta divided by a float or an int. The result|
@@ -343,13 +344,12 @@ Supported operations:
343344
| ``+t1`` | Returns a :class:`timedelta` object with the |
344345
| | same value. (2) |
345346
+--------------------------------+-----------------------------------------------+
346-
| ``-t1`` | equivalent to |
347-
| | :class:`timedelta`\ (-*t1.days*, |
348-
| | -*t1.seconds*, -*t1.microseconds*), |
349-
| | and to *t1*\* -1. (1)(4) |
347+
| ``-t1`` | Equivalent to ``timedelta(-t1.days, |
348+
| | -t1.seconds*, -t1.microseconds)``, |
349+
| | and to ``t1 * -1``. (1)(4) |
350350
+--------------------------------+-----------------------------------------------+
351-
| ``abs(t)`` | equivalent to +\ *t* when ``t.days >= 0``, |
352-
| | and to -*t* when ``t.days < 0``. (2) |
351+
| ``abs(t)`` | Equivalent to ``+t`` when ``t.days >= 0``, |
352+
| | and to ``-t`` when ``t.days < 0``. (2) |
353353
+--------------------------------+-----------------------------------------------+
354354
| ``str(t)`` | Returns a string in the form |
355355
| | ``[D day[s], ][H]H:MM:SS[.UUUUUU]``, where D |
@@ -370,10 +370,10 @@ Notes:
370370
This is exact and cannot overflow.
371371

372372
(3)
373-
Division by 0 raises :exc:`ZeroDivisionError`.
373+
Division by zero raises :exc:`ZeroDivisionError`.
374374

375375
(4)
376-
-*timedelta.max* is not representable as a :class:`timedelta` object.
376+
``-timedelta.max`` is not representable as a :class:`timedelta` object.
377377

378378
(5)
379379
String representations of :class:`timedelta` objects are normalized
@@ -583,10 +583,10 @@ Supported operations:
583583
+-------------------------------+----------------------------------------------+
584584
| Operation | Result |
585585
+===============================+==============================================+
586-
| ``date2 = date1 + timedelta`` | *date2* will be ``timedelta.days`` days |
587-
| | after *date1*. (1) |
586+
| ``date2 = date1 + timedelta`` | ``date2`` will be ``timedelta.days`` days |
587+
| | after ``date1``. (1) |
588588
+-------------------------------+----------------------------------------------+
589-
| ``date2 = date1 - timedelta`` | Computes *date2* such that ``date2 + |
589+
| ``date2 = date1 - timedelta`` | Computes ``date2`` such that ``date2 + |
590590
| | timedelta == date1``. (2) |
591591
+-------------------------------+----------------------------------------------+
592592
| ``timedelta = date1 - date2`` | \(3) |
@@ -613,8 +613,8 @@ Notes:
613613
``timedelta.seconds`` and ``timedelta.microseconds`` are ignored.
614614

615615
(3)
616-
This is exact, and cannot overflow. timedelta.seconds and
617-
timedelta.microseconds are 0, and date2 + timedelta == date1 after.
616+
This is exact, and cannot overflow. ``timedelta.seconds`` and
617+
``timedelta.microseconds`` are 0, and ``date2 + timedelta == date1`` after.
618618

619619
(4)
620620
:class:`date` objects are equal if they represent the same date.
@@ -671,7 +671,7 @@ Instance methods:
671671
time.struct_time((d.year, d.month, d.day, 0, 0, 0, d.weekday(), yday, -1))
672672

673673
where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1``
674-
is the day number within the current year starting with ``1`` for January 1st.
674+
is the day number within the current year starting with 1 for January 1st.
675675

676676

677677
.. method:: date.toordinal()
@@ -991,8 +991,8 @@ Other constructors, all class methods:
991991
.. classmethod:: datetime.fromordinal(ordinal)
992992

993993
Return the :class:`.datetime` corresponding to the proleptic Gregorian ordinal,
994-
where January 1 of year 1 has ordinal 1. :exc:`ValueError` is raised unless ``1
995-
<= ordinal <= datetime.max.toordinal()``. The hour, minute, second and
994+
where January 1 of year 1 has ordinal 1. :exc:`ValueError` is raised unless
995+
``1 <= ordinal <= datetime.max.toordinal()``. The hour, minute, second and
996996
microsecond of the result are all 0, and :attr:`.tzinfo` is ``None``.
997997

998998

@@ -1167,8 +1167,8 @@ Instance attributes (read-only):
11671167
In ``[0, 1]``. Used to disambiguate wall times during a repeated interval. (A
11681168
repeated interval occurs when clocks are rolled back at the end of daylight saving
11691169
time or when the UTC offset for the current zone is decreased for political reasons.)
1170-
The value 0 (1) represents the earlier (later) of the two moments with the same wall
1171-
time representation.
1170+
The values 0 and 1 represent, respectively, the earlier and later of the two
1171+
moments with the same wall time representation.
11721172

11731173
.. versionadded:: 3.6
11741174

@@ -1193,16 +1193,16 @@ Supported operations:
11931193
+---------------------------------------+--------------------------------+
11941194

11951195
(1)
1196-
datetime2 is a duration of timedelta removed from datetime1, moving forward in
1197-
time if ``timedelta.days`` > 0, or backward if ``timedelta.days`` < 0. The
1196+
``datetime2`` is a duration of ``timedelta`` removed from ``datetime1``, moving forward in
1197+
time if ``timedelta.days > 0``, or backward if ``timedelta.days < 0``. The
11981198
result has the same :attr:`~.datetime.tzinfo` attribute as the input datetime, and
1199-
datetime2 - datetime1 == timedelta after. :exc:`OverflowError` is raised if
1200-
datetime2.year would be smaller than :const:`MINYEAR` or larger than
1199+
``datetime2 - datetime1 == timedelta`` after. :exc:`OverflowError` is raised if
1200+
``datetime2.year`` would be smaller than :const:`MINYEAR` or larger than
12011201
:const:`MAXYEAR`. Note that no time zone adjustments are done even if the
12021202
input is an aware object.
12031203

12041204
(2)
1205-
Computes the datetime2 such that datetime2 + timedelta == datetime1. As for
1205+
Computes the ``datetime2`` such that ``datetime2 + timedelta == datetime1``. As for
12061206
addition, the result has the same :attr:`~.datetime.tzinfo` attribute as the input
12071207
datetime, and no time zone adjustments are done even if the input is aware.
12081208

@@ -1387,12 +1387,12 @@ Instance methods:
13871387
d.weekday(), yday, dst))
13881388

13891389
where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1``
1390-
is the day number within the current year starting with ``1`` for January
1390+
is the day number within the current year starting with 1 for January
13911391
1st. The :attr:`~time.struct_time.tm_isdst` flag of the result is set according to the
13921392
:meth:`dst` method: :attr:`.tzinfo` is ``None`` or :meth:`dst` returns
13931393
``None``, :attr:`!tm_isdst` is set to ``-1``; else if :meth:`dst` returns a
1394-
non-zero value, :attr:`!tm_isdst` is set to ``1``; else :attr:`!tm_isdst` is
1395-
set to ``0``.
1394+
non-zero value, :attr:`!tm_isdst` is set to 1; else :attr:`!tm_isdst` is
1395+
set to 0.
13961396

13971397

13981398
.. method:: datetime.utctimetuple()
@@ -1404,7 +1404,7 @@ Instance methods:
14041404
If *d* is aware, *d* is normalized to UTC time, by subtracting
14051405
``d.utcoffset()``, and a :class:`time.struct_time` for the
14061406
normalized time is returned. :attr:`!tm_isdst` is forced to 0. Note
1407-
that an :exc:`OverflowError` may be raised if *d*.year was
1407+
that an :exc:`OverflowError` may be raised if ``d.year`` was
14081408
``MINYEAR`` or ``MAXYEAR`` and UTC adjustment spills over a year
14091409
boundary.
14101410

@@ -1735,7 +1735,7 @@ day, and subject to adjustment via a :class:`tzinfo` object.
17351735
* ``fold in [0, 1]``.
17361736

17371737
If an argument outside those ranges is given, :exc:`ValueError` is raised. All
1738-
default to ``0`` except *tzinfo*, which defaults to :const:`None`.
1738+
default to 0 except *tzinfo*, which defaults to :const:`None`.
17391739

17401740
Class attributes:
17411741

@@ -1790,8 +1790,8 @@ Instance attributes (read-only):
17901790
In ``[0, 1]``. Used to disambiguate wall times during a repeated interval. (A
17911791
repeated interval occurs when clocks are rolled back at the end of daylight saving
17921792
time or when the UTC offset for the current zone is decreased for political reasons.)
1793-
The value 0 (1) represents the earlier (later) of the two moments with the same wall
1794-
time representation.
1793+
The values 0 and 1 represent, respectively, the earlier and later of the two
1794+
moments with the same wall time representation.
17951795

17961796
.. versionadded:: 3.6
17971797

@@ -2083,7 +2083,7 @@ Examples of working with a :class:`.time` object::
20832083
``tz.utcoffset(dt) - tz.dst(dt)``
20842084

20852085
must return the same result for every :class:`.datetime` *dt* with ``dt.tzinfo ==
2086-
tz`` For sane :class:`tzinfo` subclasses, this expression yields the time
2086+
tz``. For sane :class:`tzinfo` subclasses, this expression yields the time
20872087
zone's "standard offset", which should not depend on the date or the time, but
20882088
only on geographic location. The implementation of :meth:`datetime.astimezone`
20892089
relies on this, but cannot detect violations; it's the programmer's
@@ -2120,7 +2120,7 @@ Examples of working with a :class:`.time` object::
21202120
Return the time zone name corresponding to the :class:`.datetime` object *dt*, as
21212121
a string. Nothing about string names is defined by the :mod:`!datetime` module,
21222122
and there's no requirement that it mean anything in particular. For example,
2123-
"GMT", "UTC", "-500", "-5:00", "EDT", "US/Eastern", "America/New York" are all
2123+
``"GMT"``, ``"UTC"``, ``"-500"``, ``"-5:00"``, ``"EDT"``, ``"US/Eastern"``, ``"America/New York"`` are all
21242124
valid replies. Return ``None`` if a string name isn't known. Note that this is
21252125
a method rather than a fixed string primarily because some :class:`tzinfo`
21262126
subclasses will wish to return different names depending on the specific value
@@ -2561,11 +2561,11 @@ information, which are supported in ``datetime.strptime`` but are discarded by
25612561

25622562
For :class:`.time` objects, the format codes for year, month, and day should not
25632563
be used, as :class:`!time` objects have no such values. If they're used anyway,
2564-
``1900`` is substituted for the year, and ``1`` for the month and day.
2564+
``1900`` is substituted for the year, and 1 for the month and day.
25652565

25662566
For :class:`date` objects, the format codes for hours, minutes, seconds, and
25672567
microseconds should not be used, as :class:`date` objects have no such
2568-
values. If they're used anyway, ``0`` is substituted for them.
2568+
values. If they're used anyway, 0 is substituted for them.
25692569

25702570
For the same reason, handling of format strings containing Unicode code points
25712571
that can't be represented in the charset of the current locale is also

0 commit comments

Comments
 (0)