From f1713fd58356d2682b2f530c6de10ac09a923d53 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 27 Oct 2026 04:14:21 +0000 Subject: [PATCH 1/2] Fix errors in documentation examples --- Doc/deprecations/c-api-pending-removal-in-3.18.rst | 10 ++++++---- Doc/library/decimal.rst | 2 +- Doc/library/ftplib.rst | 2 +- Doc/library/zipapp.rst | 2 +- Doc/tutorial/errors.rst | 2 +- Doc/whatsnew/2.6.rst | 2 +- Doc/whatsnew/3.10.rst | 2 +- Doc/whatsnew/3.11.rst | 4 ++-- Doc/whatsnew/3.13.rst | 2 +- Doc/whatsnew/3.14.rst | 2 +- Doc/whatsnew/3.2.rst | 5 +++-- Doc/whatsnew/3.8.rst | 2 +- Misc/NEWS.d/3.14.0a6.rst | 10 ++++++---- 13 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Doc/deprecations/c-api-pending-removal-in-3.18.rst b/Doc/deprecations/c-api-pending-removal-in-3.18.rst index 820334ee43c82e4..d3c382ecf9090f9 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.18.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.18.rst @@ -31,11 +31,13 @@ Pending removal in Python 3.18 replace ``_PyUnicodeWriter_WriteSubstring(&writer, str, start, end)`` with :c:func:`PyUnicodeWriter_WriteSubstring(writer, str, start, end) `. * :c:func:`!_PyUnicodeWriter_WriteASCIIString`: - replace ``_PyUnicodeWriter_WriteASCIIString(&writer, str)`` with - :c:func:`PyUnicodeWriter_WriteASCII(writer, str) `. + replace ``_PyUnicodeWriter_WriteASCIIString(&writer, str, size)`` with + :c:func:`PyUnicodeWriter_WriteASCII(writer, str, size) `. * :c:func:`!_PyUnicodeWriter_WriteLatin1String`: - replace ``_PyUnicodeWriter_WriteLatin1String(&writer, str)`` with - :c:func:`PyUnicodeWriter_WriteUTF8(writer, str) `. + replace ``_PyUnicodeWriter_WriteLatin1String(&writer, str, size)`` by + decoding the string with :c:func:`PyUnicode_DecodeLatin1`, writing the + result with :c:func:`PyUnicodeWriter_WriteStr`, and releasing the result + with :c:func:`Py_DECREF`. * :c:func:`!_PyUnicodeWriter_Prepare`: (no replacement). * :c:func:`!_PyUnicodeWriter_PrepareKind`: (no replacement). * :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`. diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index d17e4e86dc337e0..93eac9083f29ddb 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -2266,7 +2266,7 @@ applied to the *result* of the computation:: Decimal('3.1416') >>> pi - Decimal('0.00005') # Subtract unrounded numbers, then round Decimal('3.1415') - >>> pi + 0 - Decimal('0.00005'). # Intermediate values are rounded + >>> pi + 0 - Decimal('0.00005') # Intermediate values are rounded Decimal('3.1416') Q: Some decimal values always print with exponential notation. Is there a way diff --git a/Doc/library/ftplib.rst b/Doc/library/ftplib.rst index e1baeff3f373bf1..a0a59868a5ace99 100644 --- a/Doc/library/ftplib.rst +++ b/Doc/library/ftplib.rst @@ -39,7 +39,7 @@ Here's a sample session using the :mod:`!ftplib` module:: drwxr-xr-x 3 1176 1176 4096 Oct 10 2012 tools '226 Directory send OK.' >>> with open('README', 'wb') as fp: - >>> ftp.retrbinary('RETR README', fp.write) + ... ftp.retrbinary('RETR README', fp.write) '226 Transfer complete.' >>> ftp.quit() '221 Goodbye.' diff --git a/Doc/library/zipapp.rst b/Doc/library/zipapp.rst index 2083857312f5e1a..1148ebec44c7872 100644 --- a/Doc/library/zipapp.rst +++ b/Doc/library/zipapp.rst @@ -227,7 +227,7 @@ fits in memory:: >>> temp = io.BytesIO() >>> zipapp.create_archive('myapp.pyz', temp, '/usr/bin/python2') >>> with open('myapp.pyz', 'wb') as f: - >>> f.write(temp.getvalue()) + ... f.write(temp.getvalue()) .. _zipapp-specifying-the-interpreter: diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 3c6edf2c4793abd..40b7dacd202deca 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -608,7 +608,7 @@ be ones that have already been raised and caught by the program, along the following pattern:: >>> excs = [] - ... for test in tests: + >>> for test in tests: ... try: ... test.run() ... except Exception as e: diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst index 3f4645d2b5b4830..f66382a704b323c 100644 --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -2600,7 +2600,7 @@ changes, or look through the Subversion logs for all the details. measured in seconds. For example:: >>> u = urllib2.urlopen("http://slow.example.com", - timeout=3) + ... timeout=3) Traceback (most recent call last): ... urllib2.URLError: diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 390b82d5a1fdc1b..2538bc697c39ef6 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -1964,7 +1964,7 @@ Changes in the C API :c:func:`PyBytes_AsString` and :c:func:`Py_CompileString`, as sketched below. (Declarations and error handling are omitted.) :: - io_module = Import_ImportModule("io"); + io_module = PyImport_ImportModule("io"); fileobject = PyObject_CallMethod(io_module, "open", "ss", filename, "rb"); source_bytes_object = PyObject_CallMethod(fileobject, "read", ""); result = PyObject_CallMethod(fileobject, "close", ""); diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 4adb5cbd1b7d3b9..b29fd050fb202bc 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -361,7 +361,7 @@ providing protection against injection attacks. For example, a SQL query function could be annotated as follows:: - def run_query(sql: LiteralString) -> ... + def run_query(sql: LiteralString) -> ...: ... def caller( @@ -2335,7 +2335,7 @@ Porting to Python 3.11 PyObject_GC_UnTrack(p); Py_TRASHCAN_SAFE_BEGIN(p); ... - Py_TRASHCAN_SAFE_END + Py_TRASHCAN_SAFE_END(p) } should migrate to the new macros as follows:: diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index d8845fe921ededa..23f464afe3f6e57 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -2733,7 +2733,7 @@ Changes in the C API PyObject_GC_UnTrack(p); Py_TRASHCAN_SAFE_BEGIN(p); ... - Py_TRASHCAN_SAFE_END + Py_TRASHCAN_SAFE_END(p) } should migrate to the new macros as follows:: diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 7190e954b9b605f..f72b1344bfdb0c8 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -403,7 +403,7 @@ function. For example: .. code-block:: python - import sys + import os, sys from tempfile import NamedTemporaryFile with NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index c61eb659ccc0f62..fc183421900c006 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -1351,8 +1351,9 @@ connection when done:: >>> from ftplib import FTP >>> with FTP("ftp1.at.proftpd.org") as ftp: - ftp.login() - ftp.dir() + ... ftp.login() + ... ftp.dir() + ... '230 Anonymous login ok, restrictions apply.' dr-xr-xr-x 9 ftp ftp 154 May 6 10:43 . diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 42d98ff94ec0d1b..b6f375866496261 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -160,7 +160,7 @@ breaking client code. For example, in the :mod:`statistics` module, the parameter name *dist* may be changed in the future. This was made possible with the following function specification:: - def quantiles(dist, /, *, n=4, method='exclusive') + def quantiles(dist, /, *, n=4, method='exclusive'): ... Since the parameters to the left of ``/`` are not exposed as possible diff --git a/Misc/NEWS.d/3.14.0a6.rst b/Misc/NEWS.d/3.14.0a6.rst index 5fb5306eeaedf56..ae3338d8337ed98 100644 --- a/Misc/NEWS.d/3.14.0a6.rst +++ b/Misc/NEWS.d/3.14.0a6.rst @@ -1398,11 +1398,13 @@ Python 3.18: replace ``_PyUnicodeWriter_WriteSubstring(&writer, str, start, end)`` with :c:func:`PyUnicodeWriter_WriteSubstring(writer, str, start, end) `. * :c:func:`!_PyUnicodeWriter_WriteASCIIString`: - replace ``_PyUnicodeWriter_WriteASCIIString(&writer, str)`` with - :c:func:`PyUnicodeWriter_WriteUTF8(writer, str) `. + replace ``_PyUnicodeWriter_WriteASCIIString(&writer, str, size)`` with + :c:func:`PyUnicodeWriter_WriteUTF8(writer, str, size) `. * :c:func:`!_PyUnicodeWriter_WriteLatin1String`: - replace ``_PyUnicodeWriter_WriteLatin1String(&writer, str)`` with - :c:func:`PyUnicodeWriter_WriteUTF8(writer, str) `. + replace ``_PyUnicodeWriter_WriteLatin1String(&writer, str, size)`` by + decoding the string with :c:func:`PyUnicode_DecodeLatin1`, writing the + result with :c:func:`PyUnicodeWriter_WriteStr`, and releasing the result + with :c:func:`Py_DECREF`. * :c:func:`!_PyUnicodeWriter_Prepare`: (no replacement). * :c:func:`!_PyUnicodeWriter_PrepareKind`: (no replacement). From 81e8d2324463bfa9b4ec649b81fdb6200b1ad8d2 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 27 Oct 2026 19:28:01 +0900 Subject: [PATCH 2/2] Apply suggestion from @StanFromIreland Co-authored-by: Stan Ulbrych --- Doc/whatsnew/3.2.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index fc183421900c006..dbc6ad9f56a0639 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -1354,7 +1354,6 @@ connection when done:: ... ftp.login() ... ftp.dir() ... - '230 Anonymous login ok, restrictions apply.' dr-xr-xr-x 9 ftp ftp 154 May 6 10:43 . dr-xr-xr-x 9 ftp ftp 154 May 6 10:43 ..