Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9542f54

Browse files
committed
Clean up nits
1. Add UTC definition into C implementation as well (just for consistency, there's no particular reason not to simply assign the alias in the Python code later). 2. Move `..versionadded` tag into the right place
1 parent 185c7ac commit 9542f54

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Doc/library/datetime.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ The :mod:`datetime` module exports the following constants:
8484
The largest year number allowed in a :class:`date` or :class:`.datetime` object.
8585
:const:`MAXYEAR` is ``9999``.
8686

87-
.. versionadded:: 3.11
8887
.. attribute:: UTC
8988

9089
Alias for the UTC timezone singleton :attr:`datetime.timezone.utc`.
9190

91+
.. versionadded:: 3.11
92+
9293
Available Types
9394
---------------
9495

Lib/datetime.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ def _name_from_offset(delta):
22902290
return f'UTC{sign}{hours:02d}:{minutes:02d}:{seconds:02d}'
22912291
return f'UTC{sign}{hours:02d}:{minutes:02d}'
22922292

2293-
timezone.utc = timezone._create(timedelta(0))
2293+
UTC = timezone.utc = timezone._create(timedelta(0))
22942294

22952295
# bpo-37642: These attributes are rounded to the nearest minute for backwards
22962296
# compatibility, even though the constructor will accept a wider range of
@@ -2515,5 +2515,3 @@ def _name_from_offset(delta):
25152515
# appropriate to maintain a single module level docstring and
25162516
# remove the following line.
25172517
from _datetime import __doc__
2518-
2519-
UTC = timezone.utc

Modules/_datetimemodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6634,6 +6634,10 @@ _datetime_exec(PyObject *module)
66346634
return -1;
66356635
}
66366636

6637+
if (PyModule_AddObjectRef(module, "UTC", PyDateTime_TimeZone_UTC) < 0) {
6638+
return -1;
6639+
}
6640+
66376641
/* A 4-year cycle has an extra leap day over what we'd get from
66386642
* pasting together 4 single years.
66396643
*/

0 commit comments

Comments
 (0)