Skip to content

Commit ed0daa7

Browse files
authored
Merge branch 'main' into enum-doc_tuple
2 parents 17c2e8d + 7e2703b commit ed0daa7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+679
-243
lines changed

‎Doc/c-api/import.rst‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,8 @@ Importing Modules
1313
single: __all__ (package variable)
1414
single: modules (in module sys)
1515
16-
This is a simplified interface to :c:func:`PyImport_ImportModuleEx` below,
17-
leaving the *globals* and *locals* arguments set to ``NULL`` and *level* set
18-
to 0. When the *name*
19-
argument contains a dot (when it specifies a submodule of a package), the
20-
*fromlist* argument is set to the list ``['*']`` so that the return value is the
21-
named module rather than the top-level package containing it as would otherwise
22-
be the case. (Unfortunately, this has an additional side effect when *name* in
23-
fact specifies a subpackage instead of a submodule: the submodules specified in
24-
the package's ``__all__`` variable are loaded.) Return a new reference to the
25-
imported module, or ``NULL`` with an exception set on failure. A failing
26-
import of a module doesn't leave the module in :data:`sys.modules`.
27-
28-
This function always uses absolute imports.
29-
16+
This is a wrapper around :c:func:`PyImport_Import()` which takes a
17+
:c:expr:`const char *` as an argument instead of a :c:expr:`PyObject *`.
3018
3119
.. c:function:: PyObject* PyImport_ImportModuleNoBlock(const char *name)
3220

‎Doc/c-api/list.rst‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,21 @@ List Objects
5656
Similar to :c:func:`PyList_Size`, but without error checking.
5757
5858
59-
.. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
59+
.. c:function:: PyObject* PyList_GetItemRef(PyObject *list, Py_ssize_t index)
6060
6161
Return the object at position *index* in the list pointed to by *list*. The
6262
position must be non-negative; indexing from the end of the list is not
63-
supported. If *index* is out of bounds (<0 or >=len(list)),
63+
supported. If *index* is out of bounds (:code:`<0 or >=len(list)`),
6464
return ``NULL`` and set an :exc:`IndexError` exception.
6565
66+
.. versionadded:: 3.13
67+
68+
69+
.. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
70+
71+
Like :c:func:`PyList_GetItemRef`, but returns a
72+
:term:`borrowed reference` instead of a :term:`strong reference`.
73+
6674
6775
.. c:function:: PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i)
6876

‎Doc/data/refcounts.dat‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,10 @@ PyList_GetItem:PyObject*::0:
11331133
PyList_GetItem:PyObject*:list:0:
11341134
PyList_GetItem:Py_ssize_t:index::
11351135

1136+
PyList_GetItemRef:PyObject*::+1:
1137+
PyList_GetItemRef:PyObject*:list:0:
1138+
PyList_GetItemRef:Py_ssize_t:index::
1139+
11361140
PyList_GetSlice:PyObject*::+1:
11371141
PyList_GetSlice:PyObject*:list:0:
11381142
PyList_GetSlice:Py_ssize_t:low::

‎Doc/data/stable_abi.dat‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Doc/library/calendar.rst‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ to interactively print a calendar.
512512
513513
python -m calendar [-h] [-L LOCALE] [-e ENCODING] [-t {text,html}]
514514
[-w WIDTH] [-l LINES] [-s SPACING] [-m MONTHS] [-c CSS]
515-
[year] [month]
515+
[-f FIRST_WEEKDAY] [year] [month]
516516
517517
518518
For example, to print a calendar for the year 2000:
@@ -586,12 +586,13 @@ The following options are accepted:
586586
or as an HTML document.
587587

588588

589-
.. option:: --first-weekday WEEKDAY, -f WEEKDAY
589+
.. option:: --first-weekday FIRST_WEEKDAY, -f FIRST_WEEKDAY
590590

591591
The weekday to start each week.
592592
Must be a number between 0 (Monday) and 6 (Sunday).
593593
Defaults to 0.
594594

595+
.. versionadded:: 3.13
595596

596597
.. option:: year
597598

‎Doc/library/datetime.rst‎

Lines changed: 50 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -400,30 +400,7 @@ objects (see below).
400400
the :func:`divmod` function. True division and multiplication of a
401401
:class:`timedelta` object by a :class:`float` object are now supported.
402402

403-
404-
Comparisons of :class:`timedelta` objects are supported, with some caveats.
405-
406-
The comparisons ``==`` or ``!=`` *always* return a :class:`bool`, no matter
407-
the type of the compared object::
408-
409-
>>> from datetime import timedelta
410-
>>> delta1 = timedelta(seconds=57)
411-
>>> delta2 = timedelta(hours=25, seconds=2)
412-
>>> delta2 != delta1
413-
True
414-
>>> delta2 == 5
415-
False
416-
417-
For all other comparisons (such as ``<`` and ``>``), when a :class:`timedelta`
418-
object is compared to an object of a different type, :exc:`TypeError`
419-
is raised::
420-
421-
>>> delta2 > delta1
422-
True
423-
>>> delta2 > 5
424-
Traceback (most recent call last):
425-
File "<stdin>", line 1, in <module>
426-
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403+
:class:`timedelta` objects support equality and order comparisons.
427404

428405
In Boolean contexts, a :class:`timedelta` object is
429406
considered to be true if and only if it isn't equal to ``timedelta(0)``.
@@ -614,8 +591,13 @@ Supported operations:
614591
+-------------------------------+----------------------------------------------+
615592
| ``timedelta = date1 - date2`` | \(3) |
616593
+-------------------------------+----------------------------------------------+
617-
| ``date1 < date2`` | *date1* is considered less than *date2* when |
618-
| | *date1* precedes *date2* in time. (4) |
594+
| | ``date1 == date2`` | Equality comparison. (4) |
595+
| | ``date1 != date2`` | |
596+
+-------------------------------+----------------------------------------------+
597+
| | ``date1 < date2`` | Order comparison. (5) |
598+
| | ``date1 > date2`` | |
599+
| | ``date1 <= date2`` | |
600+
| | ``date1 >= date2`` | |
619601
+-------------------------------+----------------------------------------------+
620602

621603
Notes:
@@ -635,15 +617,12 @@ Notes:
635617
timedelta.microseconds are 0, and date2 + timedelta == date1 after.
636618

637619
(4)
620+
:class:`date` objects are equal if they represent the same date.
621+
622+
(5)
623+
*date1* is considered less than *date2* when *date1* precedes *date2* in time.
638624
In other words, ``date1 < date2`` if and only if ``date1.toordinal() <
639-
date2.toordinal()``. Date comparison raises :exc:`TypeError` if
640-
the other comparand isn't also a :class:`date` object. However,
641-
``NotImplemented`` is returned instead if the other comparand has a
642-
:attr:`~date.timetuple` attribute. This hook gives other kinds of date objects a
643-
chance at implementing mixed-type comparison. If not, when a :class:`date`
644-
object is compared to an object of a different type, :exc:`TypeError` is raised
645-
unless the comparison is ``==`` or ``!=``. The latter cases return
646-
:const:`False` or :const:`True`, respectively.
625+
date2.toordinal()``.
647626

648627
In Boolean contexts, all :class:`date` objects are considered to be true.
649628

@@ -1170,8 +1149,13 @@ Supported operations:
11701149
+---------------------------------------+--------------------------------+
11711150
| ``timedelta = datetime1 - datetime2`` | \(3) |
11721151
+---------------------------------------+--------------------------------+
1173-
| ``datetime1 < datetime2`` | Compares :class:`.datetime` to |
1174-
| | :class:`.datetime`. (4) |
1152+
| | ``datetime1 == datetime2`` | Equality comparison. (4) |
1153+
| | ``datetime1 != datetime2`` | |
1154+
+---------------------------------------+--------------------------------+
1155+
| | ``datetime1 < datetime2`` | Order comparison. (5) |
1156+
| | ``datetime1 > datetime2`` | |
1157+
| | ``datetime1 <= datetime2`` | |
1158+
| | ``datetime1 >= datetime2`` | |
11751159
+---------------------------------------+--------------------------------+
11761160

11771161
(1)
@@ -1199,40 +1183,41 @@ Supported operations:
11991183
are done in this case.
12001184

12011185
If both are aware and have different :attr:`~.datetime.tzinfo` attributes, ``a-b`` acts
1202-
as if *a* and *b* were first converted to naive UTC datetimes first. The
1186+
as if *a* and *b* were first converted to naive UTC datetimes. The
12031187
result is ``(a.replace(tzinfo=None) - a.utcoffset()) - (b.replace(tzinfo=None)
12041188
- b.utcoffset())`` except that the implementation never overflows.
12051189

12061190
(4)
1191+
:class:`.datetime` objects are equal if they represent the same date
1192+
and time, taking into account the time zone.
1193+
1194+
Naive and aware :class:`!datetime` objects are never equal.
1195+
:class:`!datetime` objects are never equal to :class:`date` objects
1196+
that are not also :class:`!datetime` instances, even if they represent
1197+
the same date.
1198+
1199+
If both comparands are aware and have different :attr:`~.datetime.tzinfo`
1200+
attributes, the comparison acts as comparands were first converted to UTC
1201+
datetimes except that the implementation never overflows.
1202+
:class:`!datetime` instances in a repeated interval are never equal to
1203+
:class:`!datetime` instances in other time zone.
1204+
1205+
(5)
12071206
*datetime1* is considered less than *datetime2* when *datetime1* precedes
1208-
*datetime2* in time.
1207+
*datetime2* in time, taking into account the time zone.
12091208

1210-
If one comparand is naive and the other is aware, :exc:`TypeError`
1211-
is raised if an order comparison is attempted. For equality
1212-
comparisons, naive instances are never equal to aware instances.
1209+
Order comparison between naive and aware :class:`.datetime` objects,
1210+
as well as a :class:`!datetime` object and a :class:`!date` object
1211+
that is not also a :class:`!datetime` instance, raises :exc:`TypeError`.
12131212

1214-
If both comparands are aware, and have the same :attr:`~.datetime.tzinfo` attribute, the
1215-
common :attr:`~.datetime.tzinfo` attribute is ignored and the base datetimes are
1216-
compared. If both comparands are aware and have different :attr:`~.datetime.tzinfo`
1217-
attributes, the comparands are first adjusted by subtracting their UTC
1218-
offsets (obtained from ``self.utcoffset()``).
1213+
If both comparands are aware and have different :attr:`~.datetime.tzinfo`
1214+
attributes, the comparison acts as comparands were first converted to UTC
1215+
datetimes except that the implementation never overflows.
12191216

12201217
.. versionchanged:: 3.3
12211218
Equality comparisons between aware and naive :class:`.datetime`
12221219
instances don't raise :exc:`TypeError`.
12231220

1224-
.. note::
1225-
1226-
In order to stop comparison from falling back to the default scheme of comparing
1227-
object addresses, datetime comparison normally raises :exc:`TypeError` if the
1228-
other comparand isn't also a :class:`.datetime` object. However,
1229-
``NotImplemented`` is returned instead if the other comparand has a
1230-
:attr:`~.datetime.timetuple` attribute. This hook gives other kinds of date objects a
1231-
chance at implementing mixed-type comparison. If not, when a :class:`.datetime`
1232-
object is compared to an object of a different type, :exc:`TypeError` is raised
1233-
unless the comparison is ``==`` or ``!=``. The latter cases return
1234-
:const:`False` or :const:`True`, respectively.
1235-
12361221
Instance methods:
12371222

12381223
.. method:: datetime.date()
@@ -1766,21 +1751,18 @@ Instance attributes (read-only):
17661751

17671752
.. versionadded:: 3.6
17681753

1769-
:class:`.time` objects support comparison of :class:`.time` to :class:`.time`,
1770-
where *a* is considered less
1771-
than *b* when *a* precedes *b* in time. If one comparand is naive and the other
1772-
is aware, :exc:`TypeError` is raised if an order comparison is attempted. For equality
1773-
comparisons, naive instances are never equal to aware instances.
1754+
:class:`.time` objects support equality and order comparisons,
1755+
where *a* is considered less than *b* when *a* precedes *b* in time.
1756+
1757+
Naive and aware :class:`!time` objects are never equal.
1758+
Order comparison between naive and aware :class:`!time` objects raises
1759+
:exc:`TypeError`.
17741760

17751761
If both comparands are aware, and have
17761762
the same :attr:`~.time.tzinfo` attribute, the common :attr:`!tzinfo` attribute is
17771763
ignored and the base times are compared. If both comparands are aware and
17781764
have different :attr:`!tzinfo` attributes, the comparands are first adjusted by
1779-
subtracting their UTC offsets (obtained from ``self.utcoffset()``). In order
1780-
to stop mixed-type comparisons from falling back to the default comparison by
1781-
object address, when a :class:`.time` object is compared to an object of a
1782-
different type, :exc:`TypeError` is raised unless the comparison is ``==`` or
1783-
``!=``. The latter cases return :const:`False` or :const:`True`, respectively.
1765+
subtracting their UTC offsets (obtained from ``self.utcoffset()``).
17841766

17851767
.. versionchanged:: 3.3
17861768
Equality comparisons between aware and naive :class:`.time` instances

‎Doc/library/shutil.rst‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,9 @@ provided. They rely on the :mod:`zipfile` and :mod:`tarfile` modules.
586586
Create an archive file (such as zip or tar) and return its name.
587587

588588
*base_name* is the name of the file to create, including the path, minus
589-
any format-specific extension. *format* is the archive format: one of
589+
any format-specific extension.
590+
591+
*format* is the archive format: one of
590592
"zip" (if the :mod:`zlib` module is available), "tar", "gztar" (if the
591593
:mod:`zlib` module is available), "bztar" (if the :mod:`bz2` module is
592594
available), or "xztar" (if the :mod:`lzma` module is available).

‎Doc/library/stdtypes.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ between them will be implicitly converted to a single string literal. That
15281528
is, ``("spam " "eggs") == "spam eggs"``.
15291529

15301530
See :ref:`strings` for more about the various forms of string literal,
1531-
including supported escape sequences, and the ``r`` ("raw") prefix that
1531+
including supported :ref:`escape sequences <escape-sequences>`, and the ``r`` ("raw") prefix that
15321532
disables most escape sequence processing.
15331533

15341534
Strings may also be created from other objects using the :class:`str`

‎Doc/whatsnew/3.13.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,10 @@ New Features
13761376
UTF-8 encoded bytes string, rather than a :c:expr:`PyObject*`.
13771377
(Contributed by Victor Stinner in :gh:`108314`.)
13781378

1379+
* Added :c:func:`PyList_GetItemRef` function: similar to
1380+
:c:func:`PyList_GetItem` but returns a :term:`strong reference` instead of
1381+
a :term:`borrowed reference`.
1382+
13791383
* Add :c:func:`Py_IsFinalizing` function: check if the main Python interpreter is
13801384
:term:`shutting down <interpreter shutdown>`.
13811385
(Contributed by Victor Stinner in :gh:`108014`.)

‎Include/cpython/dictobject.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ typedef struct {
1717
/* Dictionary version: globally unique, value change each time
1818
the dictionary is modified */
1919
#ifdef Py_BUILD_CORE
20+
/* Bits 0-7 are for dict watchers.
21+
* Bits 8-11 are for the watched mutation counter (used by tier2 optimization)
22+
* The remaining bits (12-63) are the actual version tag. */
2023
uint64_t ma_version_tag;
2124
#else
2225
Py_DEPRECATED(3.12) uint64_t ma_version_tag;

0 commit comments

Comments
 (0)