https://github.com/python/cpython/commit/47825654dadbb80cea58d77afd66e2b9a9e92412
commit: 47825654dadbb80cea58d77afd66e2b9a9e92412
branch: 3.14
author: Inada Naoki <[email protected]>
committer: methane <[email protected]>
date: 2026-10-30T15:44:24+09:00
summary:
Doc: correct API guidance and examples (GH-160907)
(cherry picked from commit bd3be61c4a12058d7b4f8ac89804d4558ff68ea8)
files:
M Doc/builtins/functions.rst
M Doc/builtins/stdtypes.rst
M Doc/c-api/code.rst
M Doc/c-api/codec.rst
M Doc/c-api/gcsupport.rst
M Doc/extending/extending.rst
M Doc/extending/newtypes_tutorial.rst
M Doc/library/http.cookiejar.rst
M Doc/library/mailbox.rst
M Doc/library/os.rst
M Doc/library/ssl.rst
M Doc/library/tracemalloc.rst
M Doc/library/zipfile.rst
M Doc/whatsnew/3.13.rst
diff --git a/Doc/builtins/functions.rst b/Doc/builtins/functions.rst
index 221e560adc80997..8587af6f7862d34 100644
--- a/Doc/builtins/functions.rst
+++ b/Doc/builtins/functions.rst
@@ -1775,8 +1775,6 @@ are always available. They are listed here in
alphabetical order.
including the name and address of the object. A class can control what this
function returns for its instances
by defining a :meth:`~object.__repr__` method.
- If :func:`sys.displayhook` is not accessible, this function will raise
- :exc:`RuntimeError`.
This class has a custom representation that can be evaluated::
diff --git a/Doc/builtins/stdtypes.rst b/Doc/builtins/stdtypes.rst
index 813f189be9af21f..d3780ba6c83e247 100644
--- a/Doc/builtins/stdtypes.rst
+++ b/Doc/builtins/stdtypes.rst
@@ -3497,8 +3497,8 @@ objects.
If the :class:`bytearray` needs to shrink, bytes beyond *size* are
truncated.
- If the :class:`bytearray` needs to grow, all new bytes, those beyond
*size*,
- will be set to null bytes.
+ If the :class:`bytearray` needs to grow, all new bytes will be set to
null
+ bytes.
This is equivalent to:
@@ -5282,9 +5282,8 @@ Note, the non-operator versions of the
:meth:`~set.update`,
argument.
Note, the *elem* argument to the :meth:`~object.__contains__`,
-:meth:`~set.remove`, and
-:meth:`~set.discard` methods may be a set. To support searching for an
equivalent
-frozenset, a temporary one is created from *elem*.
+:meth:`~set.remove`, and :meth:`~set.discard` methods may be a set. In this
case,
+an equivalent frozenset is searched for.
.. seealso::
diff --git a/Doc/c-api/code.rst b/Doc/c-api/code.rst
index b8a13bf0a86768b..804cae3a9d97504 100644
--- a/Doc/c-api/code.rst
+++ b/Doc/c-api/code.rst
@@ -317,9 +317,9 @@ may change without deprecation warnings.
Return a new opaque index value used to adding data to code objects.
- You generally call this function once (per interpreter) and use the result
- with ``PyCode_GetExtra`` and ``PyCode_SetExtra`` to manipulate
- data on individual code objects.
+ You generally call this function once (per interpreter). Use the result with
+ :c:func:`PyUnstable_Code_GetExtra` and :c:func:`PyUnstable_Code_SetExtra`
+ to manipulate data on individual code objects.
If *free* is not ``NULL``: when a code object is deallocated,
*free* will be called on non-``NULL`` data stored under the new index.
diff --git a/Doc/c-api/codec.rst b/Doc/c-api/codec.rst
index 35ee048bd5fa9f5..6c8a764f635aa75 100644
--- a/Doc/c-api/codec.rst
+++ b/Doc/c-api/codec.rst
@@ -47,7 +47,7 @@ Codec lookup API
In the following functions, the *encoding* string is looked up converted to all
lower-case characters, which makes encodings looked up through this mechanism
-effectively case-insensitive. If no codec is found, a :exc:`KeyError` is set
+effectively case-insensitive. If no codec is found, a :exc:`LookupError` is
set
and ``NULL`` returned.
.. c:function:: PyObject* PyCodec_Encoder(const char *encoding)
diff --git a/Doc/c-api/gcsupport.rst b/Doc/c-api/gcsupport.rst
index fed795b1e8c9637..cc79c5b3b17c52f 100644
--- a/Doc/c-api/gcsupport.rst
+++ b/Doc/c-api/gcsupport.rst
@@ -127,7 +127,7 @@ rules:
.. c:macro:: PyObject_GC_Resize(TYPE, op, newsize)
- Resize an object allocated by :c:macro:`PyObject_NewVar`.
+ Resize an object allocated by :c:macro:`PyObject_GC_NewVar`.
Returns the resized object of type ``TYPE*`` (refers to any C type)
or ``NULL`` on failure.
diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst
index 6518e20cafbc9e7..38d4f18afad5fa5 100644
--- a/Doc/extending/extending.rst
+++ b/Doc/extending/extending.rst
@@ -648,6 +648,8 @@ event code, you might use the following code::
PyObject *arglist;
...
arglist = Py_BuildValue("(l)", eventcode);
+ if (arglist == NULL)
+ return NULL;
result = PyObject_CallObject(my_callback, arglist);
Py_DECREF(arglist);
if (result == NULL)
@@ -656,17 +658,24 @@ event code, you might use the following code::
Py_DECREF(result);
Note the placement of ``Py_DECREF(arglist)`` immediately after the call, before
-the error check! Also note that strictly speaking this code is not complete:
-:c:func:`Py_BuildValue` may run out of memory, and this should be checked.
+the error check!
You may also call a function with keyword arguments by using
:c:func:`PyObject_Call`, which supports arguments and keyword arguments. As in
the above example, we use :c:func:`Py_BuildValue` to construct the dictionary.
::
- PyObject *dict;
+ PyObject *arglist, *dict;
...
+ arglist = PyTuple_New(0);
+ if (arglist == NULL)
+ return NULL;
dict = Py_BuildValue("{s:i}", "name", val);
- result = PyObject_Call(my_callback, NULL, dict);
+ if (dict == NULL) {
+ Py_DECREF(arglist);
+ return NULL;
+ }
+ result = PyObject_Call(my_callback, arglist, dict);
+ Py_DECREF(arglist);
Py_DECREF(dict);
if (result == NULL)
return NULL; /* Pass error back */
diff --git a/Doc/extending/newtypes_tutorial.rst
b/Doc/extending/newtypes_tutorial.rst
index 3bbee33bd50698f..8b550a39e9209aa 100644
--- a/Doc/extending/newtypes_tutorial.rst
+++ b/Doc/extending/newtypes_tutorial.rst
@@ -898,7 +898,7 @@ function::
Before calling :c:func:`PyType_Ready`, the type structure must have the
:c:member:`~PyTypeObject.tp_base` slot filled in. When we are deriving an
existing type, it is not necessary to fill out the
:c:member:`~PyTypeObject.tp_alloc`
-slot with :c:func:`PyType_GenericNew` -- the allocation function from the base
+slot with :c:func:`PyType_GenericAlloc` -- the allocation function from the
base
type will be inherited.
After that, calling :c:func:`PyType_Ready` and adding the type object to the
diff --git a/Doc/library/http.cookiejar.rst b/Doc/library/http.cookiejar.rst
index 644ddffa05052b4..71492b5b2d7e190 100644
--- a/Doc/library/http.cookiejar.rst
+++ b/Doc/library/http.cookiejar.rst
@@ -780,7 +780,7 @@ returned::
import urllib.request
from http.cookiejar import CookieJar, DefaultCookiePolicy
policy = DefaultCookiePolicy(
- rfc2965=True, strict_ns_domain=Policy.DomainStrict,
+ rfc2965=True, strict_ns_domain=DefaultCookiePolicy.DomainStrict,
blocked_domains=["ads.net", ".ads.net"])
cj = CookieJar(policy)
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
diff --git a/Doc/library/mailbox.rst b/Doc/library/mailbox.rst
index 8cba283601a7df7..ca2c48ae44058bc 100644
--- a/Doc/library/mailbox.rst
+++ b/Doc/library/mailbox.rst
@@ -1742,6 +1742,6 @@ due to malformed messages in the mailbox::
inbox.unlock()
break # Found destination, so stop looking.
- for box in boxes.itervalues():
+ for box in boxes.values():
box.close()
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index bddc2732219374d..640b95b372852b6 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -1244,8 +1244,8 @@ as internal buffering of data.
* :const:`SEEK_SET` or ``0`` -- set *pos* relative to the beginning of the
file
* :const:`SEEK_CUR` or ``1`` -- set *pos* relative to the current file
position
* :const:`SEEK_END` or ``2`` -- set *pos* relative to the end of the file
- * :const:`SEEK_HOLE` -- set *pos* to the next data location, relative to
*pos*
- * :const:`SEEK_DATA` -- set *pos* to the next data hole, relative to *pos*
+ * :const:`SEEK_DATA` -- set *pos* to the next data location, relative to
*pos*
+ * :const:`SEEK_HOLE` -- set *pos* to the next data hole, relative to *pos*
.. versionchanged:: 3.3
diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst
index d4a19cf6f7e05ae..04d74ff427d607a 100644
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -442,7 +442,7 @@ Certificate handling
The function returns a list of (cert_bytes, encoding_type, trust) tuples.
The encoding_type specifies the encoding of cert_bytes. It is either
- :const:`x509_asn` for X.509 ASN.1 data or :const:`pkcs_7_asn` for
+ ``'x509_asn'`` for X.509 ASN.1 data or ``'pkcs_7_asn'`` for
PKCS#7 ASN.1 data. Trust specifies the purpose of the certificate as a set
of OIDS or exactly ``True`` if the certificate is trustworthy for all
purposes.
@@ -463,9 +463,9 @@ Certificate handling
one of ``CA``, ``ROOT`` or ``MY``. Windows may provide additional cert
stores, too.
- The function returns a list of (cert_bytes, encoding_type, trust) tuples.
+ The function returns a list of (cert_bytes, encoding_type) tuples.
The encoding_type specifies the encoding of cert_bytes. It is either
- :const:`x509_asn` for X.509 ASN.1 data or :const:`pkcs_7_asn` for
+ ``'x509_asn'`` for X.509 ASN.1 data or ``'pkcs_7_asn'`` for
PKCS#7 ASN.1 data.
.. availability:: Windows.
diff --git a/Doc/library/tracemalloc.rst b/Doc/library/tracemalloc.rst
index 0fa70389f1f5771..4a19acb430b0d13 100644
--- a/Doc/library/tracemalloc.rst
+++ b/Doc/library/tracemalloc.rst
@@ -655,8 +655,7 @@ StatisticDiff
.. attribute:: count_diff
Difference of number of memory blocks between the old and the new
- snapshots (``int``): ``0`` if the memory blocks have been allocated in
- the new snapshot.
+ snapshots (``int``).
.. attribute:: size
@@ -666,8 +665,7 @@ StatisticDiff
.. attribute:: size_diff
Difference of total size of memory blocks in bytes between the old and
- the new snapshots (``int``): ``0`` if the memory blocks have been
- allocated in the new snapshot.
+ the new snapshots (``int``).
.. attribute:: traceback
diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst
index 36043c355818b12..cef776b6e352ccf 100644
--- a/Doc/library/zipfile.rst
+++ b/Doc/library/zipfile.rst
@@ -761,7 +761,7 @@ The :class:`PyZipFile` constructor takes the same
parameters as the
in ``test`` directories or start with the string ``test_``, we can use a
*filterfunc* to exclude them::
- >>> zf = PyZipFile('myprog.zip')
+ >>> zf = PyZipFile('myprog.zip', 'w')
>>> def notests(s):
... fn = os.path.basename(s)
... return (not (fn == 'test' or fn.startswith('test_')))
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index d5af11040a4ce1c..01b29886b43b148 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -1805,8 +1805,8 @@ urllib
* Remove the *cafile*, *capath*, and *cadefault* parameters of the
:func:`urllib.request.urlopen` function, deprecated in Python 3.6.
Use the *context* parameter instead with an :class:`~ssl.SSLContext`
instance.
- The :meth:`ssl.SSLContext.load_cert_chain` function
- can be used to load specific certificates,
+ The :meth:`ssl.SSLContext.load_verify_locations` method
+ can be used to load specific CA certificates,
or let :func:`ssl.create_default_context` select
the operating system's trusted certificate authority (CA) certificates.
(Contributed by Victor Stinner in :gh:`105382`.)
@@ -2431,7 +2431,7 @@ Removed C APIs
* :c:func:`!PySys_AddXOption`:
Use :c:member:`PyConfig.xoptions` instead.
* :c:func:`!PySys_HasWarnOptions`:
- Use :c:member:`PyConfig.xoptions` instead.
+ Use :c:member:`PyConfig.warnoptions` instead.
* :c:func:`!PySys_SetPath`:
Set :c:member:`PyConfig.module_search_paths` instead.
* :c:func:`!Py_SetPath`:
@@ -2452,7 +2452,7 @@ Removed C APIs
They can be replaced with:
* :c:func:`PyEval_SaveThread` and :c:func:`PyEval_RestoreThread`;
- * low-level :c:func:`PyEval_AcquireThread` and
:c:func:`PyEval_RestoreThread`;
+ * low-level :c:func:`PyEval_AcquireThread` and
:c:func:`PyEval_ReleaseThread`;
* or :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release`.
(Contributed by Victor Stinner in :gh:`105182`.)
@@ -2770,8 +2770,7 @@ Changes in the C API
* Calling :c:func:`PyFrame_GetLocals` in an :term:`optimized scope`
now returns a write-through proxy rather than a snapshot
that gets updated at ill-specified times.
- If a snapshot is desired, it must be created explicitly
- (e.g. with :c:func:`PyDict_Copy`),
+ If a snapshot is desired, it must be created explicitly,
or by calling the new :c:func:`PyEval_GetFrameLocals` API.
* :c:func:`!PyFrame_FastToLocals` and
:c:func:`!PyFrame_FastToLocalsWithError`
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]