Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-101100: Fix datetime reference warnings #114661

Merged
merged 12 commits into from
Jan 29, 2024
5 changes: 5 additions & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,25 @@
nitpick_ignore = [
# Standard C functions
('c:func', 'calloc'),
('c:func', 'ctime'),
('c:func', 'dlopen'),
('c:func', 'exec'),
('c:func', 'fcntl'),
('c:func', 'fork'),
('c:func', 'free'),
('c:func', 'gettimeofday'),
('c:func', 'gmtime'),
('c:func', 'localeconv'),
('c:func', 'localtime'),
('c:func', 'main'),
('c:func', 'malloc'),
('c:func', 'mktime'),
('c:func', 'printf'),
('c:func', 'realloc'),
('c:func', 'snprintf'),
('c:func', 'sprintf'),
('c:func', 'stat'),
('c:func', 'strftime'),
('c:func', 'system'),
('c:func', 'time'),
('c:func', 'vsnprintf'),
Expand Down
72 changes: 36 additions & 36 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ Notes:
date2.toordinal()``. Date comparison raises :exc:`TypeError` if
the other comparand isn't also a :class:`date` object. However,
``NotImplemented`` is returned instead if the other comparand has a
:meth:`timetuple` attribute. This hook gives other kinds of date objects a
:meth:`timetuple<date.timetuple>` attribute. This hook gives other kinds of date objects a
serhiy-storchaka marked this conversation as resolved.
Show resolved Hide resolved
chance at implementing mixed-type comparison. If not, when a :class:`date`
object is compared to an object of a different type, :exc:`TypeError` is raised
unless the comparison is ``==`` or ``!=``. The latter cases return
Expand Down Expand Up @@ -1215,7 +1215,7 @@ Supported operations:
object addresses, datetime comparison normally raises :exc:`TypeError` if the
other comparand isn't also a :class:`.datetime` object. However,
``NotImplemented`` is returned instead if the other comparand has a
:meth:`timetuple` attribute. This hook gives other kinds of date objects a
:meth:`timetuple<date.timetuple>` attribute. This hook gives other kinds of date objects a
chance at implementing mixed-type comparison. If not, when a :class:`.datetime`
object is compared to an object of a different type, :exc:`TypeError` is raised
unless the comparison is ``==`` or ``!=``. The latter cases return
Expand Down Expand Up @@ -1347,22 +1347,22 @@ Instance methods:

where ``yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1``
is the day number within the current year starting with ``1`` for January
1st. The :attr:`tm_isdst` flag of the result is set according to the
1st. The :attr:`tm_isdst<time.struct_time.tm_isdst>` flag of the result is set according to the
serhiy-storchaka marked this conversation as resolved.
Show resolved Hide resolved
:meth:`dst` method: :attr:`.tzinfo` is ``None`` or :meth:`dst` returns
``None``, :attr:`tm_isdst` is set to ``-1``; else if :meth:`dst` returns a
non-zero value, :attr:`tm_isdst` is set to ``1``; else :attr:`tm_isdst` is
``None``, :attr:`tm_isdst<time.struct_time.tm_isdst>` is set to ``-1``; else if :meth:`dst` returns a
serhiy-storchaka marked this conversation as resolved.
Show resolved Hide resolved
non-zero value, :attr:`tm_isdst<time.struct_time.tm_isdst>` is set to ``1``; else :attr:`tm_isdst<time.struct_time.tm_isdst>` is
set to ``0``.


.. method:: datetime.utctimetuple()

If :class:`.datetime` instance *d* is naive, this is the same as
``d.timetuple()`` except that :attr:`tm_isdst` is forced to 0 regardless of what
``d.timetuple()`` except that :attr:`tm_isdst<time.struct_time.tm_isdst>` is forced to 0 regardless of what
``d.dst()`` returns. DST is never in effect for a UTC time.

If *d* is aware, *d* is normalized to UTC time, by subtracting
``d.utcoffset()``, and a :class:`time.struct_time` for the
normalized time is returned. :attr:`tm_isdst` is forced to 0. Note
normalized time is returned. :attr:`tm_isdst<time.struct_time.tm_isdst>` is forced to 0. Note
that an :exc:`OverflowError` may be raised if *d*.year was
``MINYEAR`` or ``MAXYEAR`` and UTC adjustment spills over a year
boundary.
Expand Down Expand Up @@ -2035,7 +2035,7 @@ Examples of working with a :class:`.time` object::
already been added to the UTC offset returned by :meth:`utcoffset`, so there's
no need to consult :meth:`dst` unless you're interested in obtaining DST info
separately. For example, :meth:`datetime.timetuple` calls its :attr:`~.datetime.tzinfo`
attribute's :meth:`dst` method to determine how the :attr:`tm_isdst` flag
attribute's :meth:`dst` method to determine how the :attr:`tm_isdst<time.struct_time.tm_isdst>` flag
should be set, and :meth:`tzinfo.fromutc` calls :meth:`dst` to account for
DST changes when crossing time zones.

Expand All @@ -2051,7 +2051,7 @@ Examples of working with a :class:`.time` object::
relies on this, but cannot detect violations; it's the programmer's
responsibility to ensure it. If a :class:`tzinfo` subclass cannot guarantee
this, it may be able to override the default implementation of
:meth:`tzinfo.fromutc` to work correctly with :meth:`astimezone` regardless.
:meth:`tzinfo.fromutc` to work correctly with :meth:`astimezone<datetime.astimezone>` regardless.
smontanaro marked this conversation as resolved.
Show resolved Hide resolved

Most implementations of :meth:`dst` will probably look like one of these two::

Expand Down Expand Up @@ -2128,7 +2128,7 @@ There is one more :class:`tzinfo` method that a subclass may wish to override:
different years. An example of a time zone the default :meth:`fromutc`
implementation may not handle correctly in all cases is one where the standard
offset (from UTC) depends on the specific date and time passed, which can happen
for political reasons. The default implementations of :meth:`astimezone` and
for political reasons. The default implementations of :meth:`astimezone<datetime.astimezone>` and
smontanaro marked this conversation as resolved.
Show resolved Hide resolved
:meth:`fromutc` may not produce the result you want if the result is one of the
hours straddling the moment the standard offset changes.

Expand Down Expand Up @@ -2194,7 +2194,7 @@ hour that can't be spelled unambiguously in local wall time: the last hour of
daylight time. In Eastern, that's times of the form 5:MM UTC on the day
daylight time ends. The local wall clock leaps from 1:59 (daylight time) back
to 1:00 (standard time) again. Local times of the form 1:MM are ambiguous.
:meth:`astimezone` mimics the local clock's behavior by mapping two adjacent UTC
:meth:`astimezone<datetime.astimezone>` mimics the local clock's behavior by mapping two adjacent UTC
smontanaro marked this conversation as resolved.
Show resolved Hide resolved
hours into the same local hour then. In the Eastern example, UTC times of the
form 5:MM and 6:MM both map to 1:MM when converted to Eastern, but earlier times
have the :attr:`~datetime.fold` attribute set to 0 and the later times have it set to 1.
Expand Down Expand Up @@ -2316,8 +2316,8 @@ Class attributes:

.. _strftime-strptime-behavior:

:meth:`strftime` and :meth:`strptime` Behavior
----------------------------------------------
:meth:`strftime<datetime.strftime>` and :meth:`strptime<datetime.strptime>` Behavior
------------------------------------------------------------------------------------
smontanaro marked this conversation as resolved.
Show resolved Hide resolved

:class:`date`, :class:`.datetime`, and :class:`.time` objects all support a
``strftime(format)`` method, to create a string representing the time under the
Expand All @@ -2327,8 +2327,8 @@ Conversely, the :meth:`datetime.strptime` class method creates a
:class:`.datetime` object from a string representing a date and time and a
corresponding format string.

The table below provides a high-level comparison of :meth:`strftime`
versus :meth:`strptime`:
The table below provides a high-level comparison of :meth:`strftime<datetime.strftime>`
versus :meth:`strptime<datetime.strptime>`:

+----------------+--------------------------------------------------------+------------------------------------------------------------------------------+
| | ``strftime`` | ``strptime`` |
Expand All @@ -2345,8 +2345,8 @@ versus :meth:`strptime`:

.. _format-codes:

:meth:`strftime` and :meth:`strptime` Format Codes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:meth:`strftime<datetime.strftime>` and :meth:`strptime<datetime.strptime>` Format Codes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
smontanaro marked this conversation as resolved.
Show resolved Hide resolved

These methods accept format codes that can be used to parse and format dates::

Expand Down Expand Up @@ -2485,13 +2485,13 @@ convenience. These parameters all correspond to ISO 8601 date values.
| | naive). | -03:07:12.345216 | |
+-----------+--------------------------------+------------------------+-------+

These may not be available on all platforms when used with the :meth:`strftime`
These may not be available on all platforms when used with the :meth:`strftime<datetime.strftime>`
smontanaro marked this conversation as resolved.
Show resolved Hide resolved
method. The ISO 8601 year and ISO 8601 week directives are not interchangeable
with the year and week number directives above. Calling :meth:`strptime` with
with the year and week number directives above. Calling :meth:`strptime<datetime.strptime>` with
smontanaro marked this conversation as resolved.
Show resolved Hide resolved
incomplete or ambiguous ISO 8601 directives will raise a :exc:`ValueError`.

The full set of format codes supported varies across platforms, because Python
calls the platform C library's :func:`strftime` function, and platform
calls the platform C library's :c:func:`strftime` function, and platform
variations are common. To see the full set of format codes supported on your
platform, consult the :manpage:`strftime(3)` documentation. There are also
differences between platforms in handling of unsupported format specifiers.
Expand All @@ -2507,7 +2507,7 @@ Technical Detail

Broadly speaking, ``d.strftime(fmt)`` acts like the :mod:`time` module's
``time.strftime(fmt, d.timetuple())`` although not all objects support a
:meth:`timetuple` method.
:meth:`timetuple<date.timetuple>` method.

For the :meth:`datetime.strptime` class method, the default value is
``1900-01-01T00:00:00.000``: any components not specified in the format string
Expand Down Expand Up @@ -2544,27 +2544,27 @@ Notes:
contain non-ASCII characters.

(2)
The :meth:`strptime` method can parse years in the full [1, 9999] range, but
The :meth:`strptime<datetime.strptime>` method can parse years in the full [1, 9999] range, but
years < 1000 must be zero-filled to 4-digit width.

.. versionchanged:: 3.2
In previous versions, :meth:`strftime` method was restricted to
In previous versions, :meth:`strftime<datetime.strftime>` method was restricted to
years >= 1900.

.. versionchanged:: 3.3
In version 3.2, :meth:`strftime` method was restricted to
In version 3.2, :meth:`strftime<datetime.strftime>` method was restricted to
years >= 1000.

(3)
When used with the :meth:`strptime` method, the ``%p`` directive only affects
When used with the :meth:`strptime<datetime.strptime>` method, the ``%p`` directive only affects
the output hour field if the ``%I`` directive is used to parse the hour.

(4)
Unlike the :mod:`time` module, the :mod:`datetime` module does not support
leap seconds.

(5)
When used with the :meth:`strptime` method, the ``%f`` directive
When used with the :meth:`strptime<datetime.strptime>` method, the ``%f`` directive
accepts from one to six digits and zero pads on the right. ``%f`` is
an extension to the set of format characters in the C standard (but
implemented separately in datetime objects, and therefore always
Expand All @@ -2577,22 +2577,22 @@ Notes:
For an aware object:

``%z``
:meth:`utcoffset` is transformed into a string of the form
:meth:`utcoffset<datetime.utcoffset>` is transformed into a string of the form
``±HHMM[SS[.ffffff]]``, where ``HH`` is a 2-digit string giving the number
of UTC offset hours, ``MM`` is a 2-digit string giving the number of UTC
offset minutes, ``SS`` is a 2-digit string giving the number of UTC offset
seconds and ``ffffff`` is a 6-digit string giving the number of UTC
offset microseconds. The ``ffffff`` part is omitted when the offset is a
whole number of seconds and both the ``ffffff`` and the ``SS`` part is
omitted when the offset is a whole number of minutes. For example, if
:meth:`utcoffset` returns ``timedelta(hours=-3, minutes=-30)``, ``%z`` is
:meth:`utcoffset<datetime.utcoffset>` returns ``timedelta(hours=-3, minutes=-30)``, ``%z`` is
replaced with the string ``'-0330'``.

.. versionchanged:: 3.7
The UTC offset is not restricted to a whole number of minutes.

.. versionchanged:: 3.7
When the ``%z`` directive is provided to the :meth:`strptime` method,
When the ``%z`` directive is provided to the :meth:`strptime<datetime.strptime>` method,
the UTC offsets can have a colon as a separator between hours, minutes
and seconds.
For example, ``'+01:00:00'`` will be parsed as an offset of one hour.
Expand All @@ -2603,11 +2603,11 @@ Notes:
hours, minutes and seconds.

``%Z``
In :meth:`strftime`, ``%Z`` is replaced by an empty string if
:meth:`tzname` returns ``None``; otherwise ``%Z`` is replaced by the
In :meth:`strftime<datetime.strftime>`, ``%Z`` is replaced by an empty string if
:meth:`tzname<datetime.tzname>` returns ``None``; otherwise ``%Z`` is replaced by the
returned value, which must be a string.

:meth:`strptime` only accepts certain values for ``%Z``:
:meth:`strptime<datetime.strptime>` only accepts certain values for ``%Z``:

1. any value in ``time.tzname`` for your machine's locale
2. the hard-coded values ``UTC`` and ``GMT``
Expand All @@ -2617,23 +2617,23 @@ Notes:
invalid values.

.. versionchanged:: 3.2
When the ``%z`` directive is provided to the :meth:`strptime` method, an
When the ``%z`` directive is provided to the :meth:`strptime<datetime.strptime>` method, an
aware :class:`.datetime` object will be produced. The ``tzinfo`` of the
result will be set to a :class:`timezone` instance.

(7)
When used with the :meth:`strptime` method, ``%U`` and ``%W`` are only used
When used with the :meth:`strptime<datetime.strptime>` method, ``%U`` and ``%W`` are only used
in calculations when the day of the week and the calendar year (``%Y``)
are specified.

(8)
Similar to ``%U`` and ``%W``, ``%V`` is only used in calculations when the
day of the week and the ISO year (``%G``) are specified in a
:meth:`strptime` format string. Also note that ``%G`` and ``%Y`` are not
:meth:`strptime<datetime.strptime>` format string. Also note that ``%G`` and ``%Y`` are not
interchangeable.

(9)
When used with the :meth:`strptime` method, the leading zero is optional
When used with the :meth:`strptime<datetime.strptime>` method, the leading zero is optional
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%j``, ``%U``,
``%W``, and ``%V``. Format ``%y`` does require a leading zero.

Expand Down
Loading