Skip to content

Commit 796382e

Browse files
committed
Merge branch 'main' into nedbat/split-builtin-stdlib
2 parents b3130e7 + 575fe39 commit 796382e

98 files changed

Lines changed: 1888 additions & 884 deletions

File tree

Some content is hidden

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

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ Lib/test/test_unittest/testmock/ @cjw296
630630
Doc/library/zlib.rst @StanFromIreland
631631
Lib/compression/zlib.py @StanFromIreland
632632
Lib/test/test_zlib.py @StanFromIreland
633-
Modules/_zlibmodule.c @StanFromIreland
633+
Modules/zlibmodule.c @StanFromIreland
634634

635635
# Zipfile.Path
636636
Lib/test/test_zipfile/_path/ @jaraco

.github/workflows/reusable-docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ jobs:
8686
--fail-if-regression \
8787
--fail-if-improved \
8888
--fail-if-new-news-nit
89+
- name: 'Build list of changes'
90+
run: |
91+
make -C Doc/ PYTHON=../python changes
8992
- name: 'Collect HTML IDs'
9093
if: github.event_name == 'pull_request'
9194
run: python Doc/tools/check-html-ids.py collect Doc/build/html -o Doc/build/html-ids-head.json.gz

Doc/c-api/complex.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,6 @@ the :ref:`Number Protocol <number>` API or use native complex types, like
197197
Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows.
198198
199199
.. deprecated:: 3.15
200+
201+
.. versionchanged:: next
202+
This function leaves :c:data:`errno` unchanged on success.

Doc/library/socket.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ Socket Objects
14971497
of :meth:`socket.getpeername` but not the actual OS resource. Unlike
14981498
:func:`socket.fromfd`, *fileno* will return the same socket and not a
14991499
duplicate. This may help close a detached socket using
1500-
:meth:`socket.close`.
1500+
:meth:`~socket.socket.close`.
15011501

15021502
The newly created socket is :ref:`non-inheritable <fd_inheritance>`.
15031503

@@ -1544,7 +1544,7 @@ Socket Objects
15441544

15451545
.. versionchanged:: 3.2
15461546
Support for the :term:`context manager` protocol was added. Exiting the
1547-
context manager is equivalent to calling :meth:`~socket.close`.
1547+
context manager is equivalent to calling :meth:`~socket.socket.close`.
15481548

15491549

15501550
.. method:: accept()
@@ -1769,7 +1769,7 @@ Socket Objects
17691769

17701770
Closing the file object returned by :meth:`makefile` won't close the
17711771
original socket unless all other file objects have been closed and
1772-
:meth:`socket.close` has been called on the socket object.
1772+
:meth:`~socket.socket.close` has been called on the socket object.
17731773

17741774
.. note::
17751775

Doc/library/warnings.rst

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,45 +68,48 @@ The following warnings category classes are currently defined:
6868
+----------------------------------+-----------------------------------------------+
6969
| Class | Description |
7070
+==================================+===============================================+
71-
| :exc:`Warning` | This is the base class of all warning |
72-
| | category classes. It is a subclass of |
73-
| | :exc:`Exception`. |
71+
| :exc:`Warning` | Base class for warning categories. It is a |
72+
| | subclass of :exc:`Exception`. |
7473
+----------------------------------+-----------------------------------------------+
75-
| :exc:`UserWarning` | The default category for :func:`warn`. |
74+
| :exc:`UserWarning` | Base class for warnings generated by user |
75+
| | code. The default category for :func:`warn`. |
7676
+----------------------------------+-----------------------------------------------+
77-
| :exc:`DeprecationWarning` | Base category for warnings about deprecated |
77+
| :exc:`DeprecationWarning` | Base class for warnings about deprecated |
7878
| | features when those warnings are intended for |
7979
| | other Python developers (ignored by default, |
8080
| | unless triggered by code in ``__main__``). |
8181
+----------------------------------+-----------------------------------------------+
82-
| :exc:`SyntaxWarning` | Base category for warnings about dubious |
83-
| | syntactic features (typically emitted when |
84-
| | compiling Python source code, and hence |
85-
| | may not be suppressed by runtime filters) |
82+
| :exc:`PendingDeprecationWarning` | Base class for warnings about features |
83+
| | that will be deprecated in the future |
84+
| | (ignored by default). |
8685
+----------------------------------+-----------------------------------------------+
87-
| :exc:`RuntimeWarning` | Base category for warnings about dubious |
88-
| | runtime features. |
86+
| :exc:`SyntaxWarning` | Base class for warnings about dubious syntax |
87+
| | (typically emitted when compiling Python |
88+
| | source code, and hence may not be suppressed |
89+
| | by runtime filters). |
8990
+----------------------------------+-----------------------------------------------+
90-
| :exc:`FutureWarning` | Base category for warnings about deprecated |
91+
| :exc:`RuntimeWarning` | Base class for warnings about dubious runtime |
92+
| | behavior. |
93+
+----------------------------------+-----------------------------------------------+
94+
| :exc:`FutureWarning` | Base class for warnings about deprecated |
9195
| | features when those warnings are intended for |
9296
| | end users of applications that are written in |
9397
| | Python. |
9498
+----------------------------------+-----------------------------------------------+
95-
| :exc:`PendingDeprecationWarning` | Base category for warnings about features |
96-
| | that will be deprecated in the future |
97-
| | (ignored by default). |
98-
+----------------------------------+-----------------------------------------------+
99-
| :exc:`ImportWarning` | Base category for warnings triggered during |
99+
| :exc:`ImportWarning` | Base class for warnings triggered during |
100100
| | the process of importing a module (ignored by |
101101
| | default). |
102102
+----------------------------------+-----------------------------------------------+
103-
| :exc:`UnicodeWarning` | Base category for warnings related to |
103+
| :exc:`UnicodeWarning` | Base class for warnings related to |
104104
| | Unicode. |
105105
+----------------------------------+-----------------------------------------------+
106-
| :exc:`BytesWarning` | Base category for warnings related to |
106+
| :exc:`EncodingWarning` | Base class for warnings related to encodings. |
107+
| | See :ref:`io-encoding-warning` for details. |
108+
+----------------------------------+-----------------------------------------------+
109+
| :exc:`BytesWarning` | Base class for warnings related to |
107110
| | :class:`bytes` and :class:`bytearray`. |
108111
+----------------------------------+-----------------------------------------------+
109-
| :exc:`ResourceWarning` | Base category for warnings related to |
112+
| :exc:`ResourceWarning` | Base class for warnings related to |
110113
| | resource usage (ignored by default). |
111114
+----------------------------------+-----------------------------------------------+
112115

Doc/tools/extensions/changes.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from docutils import nodes
88
from sphinx import addnodes
9+
from sphinx.builders.changes import ChangesBuilder
910
from sphinx.domains.changeset import (
1011
VersionChange,
1112
versionlabel_classes,
@@ -17,6 +18,7 @@
1718
if TYPE_CHECKING:
1819
from docutils.nodes import Node
1920
from sphinx.application import Sphinx
21+
from sphinx.environment import BuildEnvironment
2022
from sphinx.util.typing import ExtensionMetadata
2123

2224

@@ -146,6 +148,32 @@ def _add_glossary_link(cls, inline: nodes.inline) -> None:
146148
break
147149

148150

151+
def _fixup_changesets(app: Sphinx, env: BuildEnvironment) -> None:
152+
changesets = env.get_domain("changeset").changesets
153+
154+
# The changeset domain records each entry's plain text before SoftDeprecated
155+
# replaces the :term:, so strip the markup before the changes builder renders it.
156+
for entries in changesets.values():
157+
for i, entry in enumerate(entries):
158+
if entry.type == "soft-deprecated":
159+
entries[i] = entry._replace(
160+
content=SoftDeprecated._TERM_RE.sub(r"\1", entry.content)
161+
)
162+
163+
# DeprecatedRemoved entries are recorded under their (deprecated,
164+
# removed) version tuple, which the changes builder ignores.
165+
# Re-file them under both versions.
166+
for versions in [v for v in changesets if isinstance(v, tuple)]:
167+
deprecated, removed = versions
168+
for entry in changesets.pop(versions):
169+
changesets.setdefault(deprecated, []).append(
170+
entry._replace(type="deprecated")
171+
)
172+
changesets.setdefault(removed, []).append(
173+
entry._replace(type="versionremoved")
174+
)
175+
176+
149177
def setup(app: Sphinx) -> ExtensionMetadata:
150178
# Override Sphinx's directives with support for 'next'
151179
app.add_directive("versionadded", PyVersionChange, override=True)
@@ -155,9 +183,15 @@ def setup(app: Sphinx) -> ExtensionMetadata:
155183

156184
# Register the ``.. deprecated-removed::`` directive
157185
app.add_directive("deprecated-removed", DeprecatedRemoved)
186+
# _fixup_changesets() changes these entries to 'deprecated'/'versionremoved'
187+
ChangesBuilder.typemap["deprecated-removed"] = "deprecated-removed"
158188

159189
# Register the ``.. soft-deprecated::`` directive
160190
app.add_directive("soft-deprecated", SoftDeprecated)
191+
ChangesBuilder.typemap["soft-deprecated"] = "soft deprecated"
192+
193+
# Repair the recorded changesets for the couple of custom directives above
194+
app.connect("env-updated", _fixup_changesets)
161195

162196
return {
163197
"version": "1.0",

Doc/whatsnew/3.16.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,10 @@ Porting to Python 3.16
10181018
if the value cannot be marshalled.
10191019
(Contributed by Serhiy Storchaka in :gh:`155907`.)
10201020

1021+
* :c:func:`_Py_c_abs` no longer sets :c:data:`errno` to zero on success,
1022+
but rather leaves it unchanged.
1023+
(Contributed by Sergey B Kirpichev in :gh:`155526`.)
1024+
10211025
Deprecated C APIs
10221026
-----------------
10231027

Include/internal/pycore_bytesobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ PyAPI_FUNC(PyObject *) _PyBytes_Repeat(PyObject *self, Py_ssize_t n);
7575
*/
7676
#define _PyBytesObject_SIZE (offsetof(PyBytesObject, ob_sval) + 1)
7777

78+
extern int _PyBytes_ResizeKeepOnError(PyObject **pv, Py_ssize_t newsize);
79+
7880
/* --- PyBytesWriter ------------------------------------------------------ */
7981

8082
struct PyBytesWriter {

Lib/asyncio/tasks.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ def __step(self, exc=None):
268268
raise exceptions.InvalidStateError(
269269
f'__step(): already done: {self!r}, {exc!r}')
270270
if self._must_cancel:
271-
if not isinstance(exc, exceptions.CancelledError):
271+
# gh-108549: do not swallow SystemExit and KeyboardInterrupt.
272+
if not isinstance(exc, (exceptions.CancelledError,
273+
SystemExit, KeyboardInterrupt)):
272274
exc = self._make_cancelled_error()
273275
self._must_cancel = False
274276
self._fut_waiter = None
@@ -541,13 +543,18 @@ async def _cancel_and_wait(fut):
541543
cb = functools.partial(_release_waiter, waiter)
542544
fut.add_done_callback(cb)
543545

546+
# gh-157058: awaiting the waiter leaves no edge on fut, add it here
547+
cur_task = current_task()
548+
futures.future_add_to_awaited_by(fut, cur_task)
549+
544550
try:
545551
fut.cancel()
546552
# We cannot wait on *fut* directly to make
547553
# sure _cancel_and_wait itself is reliably cancellable.
548554
await waiter
549555
finally:
550556
fut.remove_done_callback(cb)
557+
futures.future_discard_from_awaited_by(fut, cur_task)
551558

552559

553560
class _AsCompletedIterator:
@@ -770,6 +777,11 @@ def cancel(self, msg=None):
770777
return ret
771778

772779

780+
def _discard_awaited_by(children, waiter, outer):
781+
for fut in children:
782+
futures.future_discard_from_awaited_by(fut, waiter)
783+
784+
773785
def gather(*coros_or_futures, return_exceptions=False):
774786
"""Return a future aggregating results from the given coroutines/futures.
775787
@@ -903,6 +915,10 @@ def _done_callback(fut, cur_task=cur_task):
903915
children.append(fut)
904916

905917
outer = _GatheringFuture(children, loop=loop)
918+
if cur_task is not None:
919+
# gh-157213: a child outliving gather() must lose the awaited-by edge
920+
outer.add_done_callback(
921+
functools.partial(_discard_awaited_by, children, cur_task))
906922
# Run done callbacks after GatheringFuture created so any post-processing
907923
# can be performed at this point
908924
# optimization: in the special case that *all* futures finished eagerly,

Lib/base64.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ def b16decode(s, casefold=False, *, ignorechars=b''):
304304
for b in b'abcdef':
305305
if b in s and b not in ignorechars:
306306
raise binascii.Error('Non-base16 digit found')
307-
s = s.translate(None, delete=b'abcdef')
307+
if ignorechars:
308+
s = s.translate(None, delete=b'abcdef')
308309
return binascii.unhexlify(s, ignorechars=ignorechars)
309310

310311
#

0 commit comments

Comments
 (0)