Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb679a0

Browse files
committed
Merge branch 'master' into speedup-Fraction-fromstr/72902
2 parents 7c567fc + 9983c7d commit cb679a0

File tree

73 files changed

+1416
-1803
lines changed

Some content is hidden

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

73 files changed

+1416
-1803
lines changed

Doc/c-api/gcsupport.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ provided. In order to use this macro, the :c:member:`~PyTypeObject.tp_traverse`
180180
must name its arguments exactly *visit* and *arg*:
181181
182182
183-
.. c:function:: void Py_VISIT(PyObject *o)
183+
.. c:macro:: Py_VISIT(o)
184184
185-
If *o* is not ``NULL``, call the *visit* callback, with arguments *o*
185+
If the :c:expr:`PyObject *` *o* is not ``NULL``, call the *visit* callback, with arguments *o*
186186
and *arg*. If *visit* returns a non-zero value, then return it.
187187
Using this macro, :c:member:`~PyTypeObject.tp_traverse` handlers
188188
look like::

Doc/c-api/init.rst

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,36 @@ Note that the ``PyGILState_*`` functions assume there is only one global
919919
interpreter (created automatically by :c:func:`Py_Initialize`). Python
920920
supports the creation of additional interpreters (using
921921
:c:func:`Py_NewInterpreter`), but mixing multiple interpreters and the
922-
``PyGILState_*`` API is unsupported.
922+
``PyGILState_*`` API is unsupported. This is because :c:func:`PyGILState_Ensure`
923+
and similar functions default to :term:`attaching <attached thread state>` a
924+
:term:`thread state` for the main interpreter, meaning that the thread can't safely
925+
interact with the calling subinterpreter.
926+
927+
Supporting subinterpreters in non-Python threads
928+
------------------------------------------------
929+
930+
If you would like to support subinterpreters with non-Python created threads, you
931+
must use the ``PyThreadState_*`` API instead of the traditional ``PyGILState_*``
932+
API.
933+
934+
In particular, you must store the interpreter state from the calling
935+
function and pass it to :c:func:`PyThreadState_New`, which will ensure that
936+
the :term:`thread state` is targeting the correct interpreter::
937+
938+
/* The return value of PyInterpreterState_Get() from the
939+
function that created this thread. */
940+
PyInterpreterState *interp = ThreadData->interp;
941+
PyThreadState *tstate = PyThreadState_New(interp);
942+
PyThreadState_Swap(tstate);
943+
944+
/* GIL of the subinterpreter is now held.
945+
Perform Python actions here. */
946+
result = CallSomeFunction();
947+
/* evaluate result or handle exception */
923948
949+
/* Destroy the thread state. No Python API allowed beyond this point. */
950+
PyThreadState_Clear(tstate);
951+
PyThreadState_DeleteCurrent();
924952
925953
.. _fork-and-threads:
926954
@@ -1097,6 +1125,10 @@ code, or when embedding the Python interpreter:
10971125
.. seealso:
10981126
:c:func:`PyEval_ReleaseThread`
10991127
1128+
.. note::
1129+
Similar to :c:func:`PyGILState_Ensure`, this function will hang the
1130+
thread if the runtime is finalizing.
1131+
11001132
11011133
The following functions use thread-local storage, and are not compatible
11021134
with sub-interpreters:
@@ -1123,10 +1155,10 @@ with sub-interpreters:
11231155
When the function returns, there will be an :term:`attached thread state`
11241156
and the thread will be able to call arbitrary Python code. Failure is a fatal error.
11251157
1126-
.. note::
1127-
Calling this function from a thread when the runtime is finalizing will
1128-
hang the thread until the program exits, even if the thread was not
1129-
created by Python. Refer to
1158+
.. warning::
1159+
Calling this function when the runtime is finalizing is unsafe. Doing
1160+
so will either hang the thread until the program ends, or fully crash
1161+
the interpreter in rare cases. Refer to
11301162
:ref:`cautions-regarding-runtime-finalization` for more details.
11311163
11321164
.. versionchanged:: 3.14
@@ -1143,28 +1175,37 @@ with sub-interpreters:
11431175
Every call to :c:func:`PyGILState_Ensure` must be matched by a call to
11441176
:c:func:`PyGILState_Release` on the same thread.
11451177
1146-
11471178
.. c:function:: PyThreadState* PyGILState_GetThisThreadState()
11481179
11491180
Get the :term:`attached thread state` for this thread. May return ``NULL`` if no
11501181
GILState API has been used on the current thread. Note that the main thread
11511182
always has such a thread-state, even if no auto-thread-state call has been
11521183
made on the main thread. This is mainly a helper/diagnostic function.
11531184
1154-
.. seealso: :c:func:`PyThreadState_Get``
1185+
.. note::
1186+
This function does not account for :term:`thread states <thread state>` created
1187+
by something other than :c:func:`PyGILState_Ensure` (such as :c:func:`PyThreadState_New`).
1188+
Prefer :c:func:`PyThreadState_Get` or :c:func:`PyThreadState_GetUnchecked`
1189+
for most cases.
11551190
1191+
.. seealso: :c:func:`PyThreadState_Get``
11561192
11571193
.. c:function:: int PyGILState_Check()
11581194
11591195
Return ``1`` if the current thread is holding the :term:`GIL` and ``0`` otherwise.
11601196
This function can be called from any thread at any time.
1161-
Only if it has had its Python thread state initialized and currently is
1162-
holding the :term:`GIL` will it return ``1``.
1197+
Only if it has had its :term:`thread state <attached thread state>` initialized
1198+
via :c:func:`PyGILState_Ensure` will it return ``1``.
11631199
This is mainly a helper/diagnostic function. It can be useful
11641200
for example in callback contexts or memory allocation functions when
11651201
knowing that the :term:`GIL` is locked can allow the caller to perform sensitive
11661202
actions or otherwise behave differently.
11671203
1204+
.. note::
1205+
If the current Python process has ever created a subinterpreter, this
1206+
function will *always* return ``1``. Prefer :c:func:`PyThreadState_GetUnchecked`
1207+
for most cases.
1208+
11681209
.. versionadded:: 3.4
11691210
11701211

Doc/deprecations/pending-removal-in-3.15.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Pending removal in Python 3.15
2020

2121
* :mod:`http.server`:
2222

23-
* The obsolete and rarely used :class:`~http.server.CGIHTTPRequestHandler`
23+
* The obsolete and rarely used :class:`!CGIHTTPRequestHandler`
2424
has been deprecated since Python 3.13.
2525
No direct replacement exists.
2626
*Anything* is better than CGI to interface
@@ -51,7 +51,7 @@ Pending removal in Python 3.15
5151

5252
* :mod:`platform`:
5353

54-
* :func:`~platform.java_ver` has been deprecated since Python 3.13.
54+
* :func:`!platform.java_ver` has been deprecated since Python 3.13.
5555
This function is only useful for Jython support, has a confusing API,
5656
and is largely untested.
5757

Doc/faq/design.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,12 @@ strings representing the files in the current directory. Functions which
420420
operate on this output would generally not break if you added another file or
421421
two to the directory.
422422

423-
Tuples are immutable, meaning that once a tuple has been created, you can't
424-
replace any of its elements with a new value. Lists are mutable, meaning that
425-
you can always change a list's elements. Only immutable elements can be used as
426-
dictionary keys, and hence only tuples and not lists can be used as keys.
423+
Tuples are :term:`immutable`, meaning that once a tuple has been created, you can't
424+
replace any of its elements with a new value. Lists are :term:`mutable`, meaning that
425+
you can always change a list's elements. Only :term:`hashable` objects can
426+
be used as dictionary keys. Most immutable types are hashable, which is why
427+
tuples, but not lists, can be used as keys. Note, however, that a tuple is
428+
only hashable if all of its elements are hashable.
427429

428430

429431
How are lists implemented in CPython?

Doc/howto/functional.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ have the form::
372372
for expr2 in sequence2
373373
if condition2
374374
for expr3 in sequence3
375-
...
376375
if condition3
376+
...
377377
for exprN in sequenceN
378378
if conditionN )
379379

Doc/library/asyncio-dev.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ In addition to enabling the debug mode, consider also:
4646

4747
When the debug mode is enabled:
4848

49-
* asyncio checks for :ref:`coroutines that were not awaited
50-
<asyncio-coroutine-not-scheduled>` and logs them; this mitigates
51-
the "forgotten await" pitfall.
52-
5349
* Many non-threadsafe asyncio APIs (such as :meth:`loop.call_soon` and
5450
:meth:`loop.call_at` methods) raise an exception if they are called
5551
from a wrong thread.

Doc/library/dataclasses.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ Module contents
304304

305305
.. versionadded:: 3.10
306306

307-
- ``doc``: optional docstring for this field.
307+
- *doc*: optional docstring for this field.
308308

309-
.. versionadded:: 3.13
309+
.. versionadded:: 3.14
310310

311311
If the default value of a field is specified by a call to
312312
:func:`!field`, then the class attribute for this field will be

Doc/library/http.server.rst

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ instantiation, of which this module provides three different variants:
429429
``'Last-Modified:'`` header with the file's modification time.
430430

431431
Then follows a blank line signifying the end of the headers, and then the
432-
contents of the file are output. If the file's MIME type starts with
433-
``text/`` the file is opened in text mode; otherwise binary mode is used.
432+
contents of the file are output.
434433

435434
For example usage, see the implementation of the ``test`` function
436435
in :source:`Lib/http/server.py`.
@@ -459,55 +458,6 @@ such as using different index file names by overriding the class attribute
459458
:attr:`index_pages`.
460459

461460

462-
.. class:: CGIHTTPRequestHandler(request, client_address, server)
463-
464-
This class is used to serve either files or output of CGI scripts from the
465-
current directory and below. Note that mapping HTTP hierarchic structure to
466-
local directory structure is exactly as in :class:`SimpleHTTPRequestHandler`.
467-
468-
.. note::
469-
470-
CGI scripts run by the :class:`CGIHTTPRequestHandler` class cannot execute
471-
redirects (HTTP code 302), because code 200 (script output follows) is
472-
sent prior to execution of the CGI script. This pre-empts the status
473-
code.
474-
475-
The class will however, run the CGI script, instead of serving it as a file,
476-
if it guesses it to be a CGI script. Only directory-based CGI are used ---
477-
the other common server configuration is to treat special extensions as
478-
denoting CGI scripts.
479-
480-
The :func:`do_GET` and :func:`do_HEAD` functions are modified to run CGI scripts
481-
and serve the output, instead of serving files, if the request leads to
482-
somewhere below the ``cgi_directories`` path.
483-
484-
The :class:`CGIHTTPRequestHandler` defines the following data member:
485-
486-
.. attribute:: cgi_directories
487-
488-
This defaults to ``['/cgi-bin', '/htbin']`` and describes directories to
489-
treat as containing CGI scripts.
490-
491-
The :class:`CGIHTTPRequestHandler` defines the following method:
492-
493-
.. method:: do_POST()
494-
495-
This method serves the ``'POST'`` request type, only allowed for CGI
496-
scripts. Error 501, "Can only POST to CGI scripts", is output when trying
497-
to POST to a non-CGI url.
498-
499-
Note that CGI scripts will be run with UID of user nobody, for security
500-
reasons. Problems with the CGI script will be translated to error 403.
501-
502-
.. deprecated-removed:: 3.13 3.15
503-
504-
:class:`CGIHTTPRequestHandler` is being removed in 3.15. CGI has not
505-
been considered a good way to do things for well over a decade. This code
506-
has been unmaintained for a while now and sees very little practical use.
507-
Retaining it could lead to further :ref:`security considerations
508-
<http.server-security>`.
509-
510-
511461
.. _http-server-cli:
512462

513463
Command-line interface
@@ -564,24 +514,6 @@ The following options are accepted:
564514

565515
.. versionadded:: 3.11
566516

567-
.. option:: --cgi
568-
569-
:class:`CGIHTTPRequestHandler` can be enabled in the command line by passing
570-
the ``--cgi`` option::
571-
572-
python -m http.server --cgi
573-
574-
.. deprecated-removed:: 3.13 3.15
575-
576-
:mod:`http.server` command line ``--cgi`` support is being removed
577-
because :class:`CGIHTTPRequestHandler` is being removed.
578-
579-
.. warning::
580-
581-
:class:`CGIHTTPRequestHandler` and the ``--cgi`` command-line option
582-
are not intended for use by untrusted clients and may be vulnerable
583-
to exploitation. Always use within a secure environment.
584-
585517
.. option:: --tls-cert
586518

587519
Specifies a TLS certificate chain for HTTPS connections::

Doc/library/json.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ is a lightweight data interchange format inspired by
1818
`JavaScript <https://en.wikipedia.org/wiki/JavaScript>`_ object literal syntax
1919
(although it is not a strict subset of JavaScript [#rfc-errata]_ ).
2020

21+
.. note::
22+
The term "object" in the context of JSON processing in Python can be
23+
ambiguous. All values in Python are objects. In JSON, an object refers to
24+
any data wrapped in curly braces, similar to a Python dictionary.
25+
2126
.. warning::
2227
Be cautious when parsing JSON data from untrusted sources. A malicious
2328
JSON string may cause the decoder to consume considerable CPU and memory
2429
resources. Limiting the size of data to be parsed is recommended.
2530

26-
:mod:`json` exposes an API familiar to users of the standard library
31+
This module exposes an API familiar to users of the standard library
2732
:mod:`marshal` and :mod:`pickle` modules.
2833

2934
Encoding basic Python object hierarchies::
@@ -60,7 +65,7 @@ Pretty printing::
6065
"6": 7
6166
}
6267

63-
Specializing JSON object encoding::
68+
Customizing JSON object encoding::
6469

6570
>>> import json
6671
>>> def custom_json(obj):
@@ -83,7 +88,7 @@ Decoding JSON::
8388
>>> json.load(io)
8489
['streaming API']
8590

86-
Specializing JSON object decoding::
91+
Customizing JSON object decoding::
8792

8893
>>> import json
8994
>>> def as_complex(dct):
@@ -279,7 +284,7 @@ Basic Usage
279284

280285
:param object_hook:
281286
If set, a function that is called with the result of
282-
any object literal decoded (a :class:`dict`).
287+
any JSON object literal decoded (a :class:`dict`).
283288
The return value of this function will be used
284289
instead of the :class:`dict`.
285290
This feature can be used to implement custom decoders,
@@ -289,7 +294,7 @@ Basic Usage
289294

290295
:param object_pairs_hook:
291296
If set, a function that is called with the result of
292-
any object literal decoded with an ordered list of pairs.
297+
any JSON object literal decoded with an ordered list of pairs.
293298
The return value of this function will be used
294299
instead of the :class:`dict`.
295300
This feature can be used to implement custom decoders.

Doc/library/pathlib.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,9 +1781,12 @@ The following wildcards are supported in patterns for
17811781
``?``
17821782
Matches one non-separator character.
17831783
``[seq]``
1784-
Matches one character in *seq*.
1784+
Matches one character in *seq*, where *seq* is a sequence of characters.
1785+
Range expressions are supported; for example, ``[a-z]`` matches any lowercase ASCII letter.
1786+
Multiple ranges can be combined: ``[a-zA-Z0-9_]`` matches any ASCII letter, digit, or underscore.
1787+
17851788
``[!seq]``
1786-
Matches one character not in *seq*.
1789+
Matches one character not in *seq*, where *seq* follows the same rules as above.
17871790

17881791
For a literal match, wrap the meta-characters in brackets.
17891792
For example, ``"[?]"`` matches the character ``"?"``.

Doc/library/platform.rst

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,6 @@ Cross platform
188188
:attr:`processor` is resolved late instead of immediately.
189189

190190

191-
Java platform
192-
-------------
193-
194-
195-
.. function:: java_ver(release='', vendor='', vminfo=('','',''), osinfo=('','',''))
196-
197-
Version interface for Jython.
198-
199-
Returns a tuple ``(release, vendor, vminfo, osinfo)`` with *vminfo* being a
200-
tuple ``(vm_name, vm_release, vm_vendor)`` and *osinfo* being a tuple
201-
``(os_name, os_version, os_arch)``. Values which cannot be determined are set to
202-
the defaults given as parameters (which all default to ``''``).
203-
204-
.. deprecated-removed:: 3.13 3.15
205-
It was largely untested, had a confusing API,
206-
and was only useful for Jython support.
207-
208-
209191
Windows platform
210192
----------------
211193

0 commit comments

Comments
 (0)