Skip to content

Commit 085d366

Browse files
Doc: Fix errors in documentation examples (#160742)
Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent b566053 commit 085d366

13 files changed

Lines changed: 26 additions & 22 deletions

File tree

‎Doc/deprecations/c-api-pending-removal-in-3.18.rst‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ Pending removal in Python 3.18
3131
replace ``_PyUnicodeWriter_WriteSubstring(&writer, str, start, end)`` with
3232
:c:func:`PyUnicodeWriter_WriteSubstring(writer, str, start, end) <PyUnicodeWriter_WriteSubstring>`.
3333
* :c:func:`!_PyUnicodeWriter_WriteASCIIString`:
34-
replace ``_PyUnicodeWriter_WriteASCIIString(&writer, str)`` with
35-
:c:func:`PyUnicodeWriter_WriteASCII(writer, str) <PyUnicodeWriter_WriteASCII>`.
34+
replace ``_PyUnicodeWriter_WriteASCIIString(&writer, str, size)`` with
35+
:c:func:`PyUnicodeWriter_WriteASCII(writer, str, size) <PyUnicodeWriter_WriteASCII>`.
3636
* :c:func:`!_PyUnicodeWriter_WriteLatin1String`:
37-
replace ``_PyUnicodeWriter_WriteLatin1String(&writer, str)`` with
38-
:c:func:`PyUnicodeWriter_WriteUTF8(writer, str) <PyUnicodeWriter_WriteUTF8>`.
37+
replace ``_PyUnicodeWriter_WriteLatin1String(&writer, str, size)`` by
38+
decoding the string with :c:func:`PyUnicode_DecodeLatin1`, writing the
39+
result with :c:func:`PyUnicodeWriter_WriteStr`, and releasing the result
40+
with :c:func:`Py_DECREF`.
3941
* :c:func:`!_PyUnicodeWriter_Prepare`: (no replacement).
4042
* :c:func:`!_PyUnicodeWriter_PrepareKind`: (no replacement).
4143
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.

‎Doc/library/decimal.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ applied to the *result* of the computation::
22662266
Decimal('3.1416')
22672267
>>> pi - Decimal('0.00005') # Subtract unrounded numbers, then round
22682268
Decimal('3.1415')
2269-
>>> pi + 0 - Decimal('0.00005'). # Intermediate values are rounded
2269+
>>> pi + 0 - Decimal('0.00005') # Intermediate values are rounded
22702270
Decimal('3.1416')
22712271

22722272
Q: Some decimal values always print with exponential notation. Is there a way

‎Doc/library/ftplib.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Here's a sample session using the :mod:`!ftplib` module::
3939
drwxr-xr-x 3 1176 1176 4096 Oct 10 2012 tools
4040
'226 Directory send OK.'
4141
>>> with open('README', 'wb') as fp:
42-
>>> ftp.retrbinary('RETR README', fp.write)
42+
... ftp.retrbinary('RETR README', fp.write)
4343
'226 Transfer complete.'
4444
>>> ftp.quit()
4545
'221 Goodbye.'

‎Doc/library/zipapp.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fits in memory::
227227
>>> temp = io.BytesIO()
228228
>>> zipapp.create_archive('myapp.pyz', temp, '/usr/bin/python2')
229229
>>> with open('myapp.pyz', 'wb') as f:
230-
>>> f.write(temp.getvalue())
230+
... f.write(temp.getvalue())
231231

232232

233233
.. _zipapp-specifying-the-interpreter:

‎Doc/tutorial/errors.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ be ones that have already been raised and caught by the program, along
608608
the following pattern::
609609

610610
>>> excs = []
611-
... for test in tests:
611+
>>> for test in tests:
612612
... try:
613613
... test.run()
614614
... except Exception as e:

‎Doc/whatsnew/2.6.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ changes, or look through the Subversion logs for all the details.
26002600
measured in seconds. For example::
26012601

26022602
>>> u = urllib2.urlopen("http://slow.example.com",
2603-
timeout=3)
2603+
... timeout=3)
26042604
Traceback (most recent call last):
26052605
...
26062606
urllib2.URLError: <urlopen error timed out>

‎Doc/whatsnew/3.10.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,7 @@ Changes in the C API
19641964
:c:func:`PyBytes_AsString` and :c:func:`Py_CompileString`,
19651965
as sketched below. (Declarations and error handling are omitted.) ::
19661966
1967-
io_module = Import_ImportModule("io");
1967+
io_module = PyImport_ImportModule("io");
19681968
fileobject = PyObject_CallMethod(io_module, "open", "ss", filename, "rb");
19691969
source_bytes_object = PyObject_CallMethod(fileobject, "read", "");
19701970
result = PyObject_CallMethod(fileobject, "close", "");

‎Doc/whatsnew/3.11.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ providing protection against injection attacks.
361361

362362
For example, a SQL query function could be annotated as follows::
363363

364-
def run_query(sql: LiteralString) -> ...
364+
def run_query(sql: LiteralString) -> ...:
365365
...
366366

367367
def caller(
@@ -2335,7 +2335,7 @@ Porting to Python 3.11
23352335
PyObject_GC_UnTrack(p);
23362336
Py_TRASHCAN_SAFE_BEGIN(p);
23372337
...
2338-
Py_TRASHCAN_SAFE_END
2338+
Py_TRASHCAN_SAFE_END(p)
23392339
}
23402340

23412341
should migrate to the new macros as follows::

‎Doc/whatsnew/3.13.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,7 @@ Changes in the C API
27332733
PyObject_GC_UnTrack(p);
27342734
Py_TRASHCAN_SAFE_BEGIN(p);
27352735
...
2736-
Py_TRASHCAN_SAFE_END
2736+
Py_TRASHCAN_SAFE_END(p)
27372737
}
27382738

27392739
should migrate to the new macros as follows::

‎Doc/whatsnew/3.14.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ function. For example:
403403

404404
.. code-block:: python
405405
406-
import sys
406+
import os, sys
407407
from tempfile import NamedTemporaryFile
408408
409409
with NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:

0 commit comments

Comments
 (0)