Skip to content

Commit 1f854ee

Browse files
authored
Merge branch 'main' into static-bltin-__module__-115231
2 parents be1c7ef + 597fad0 commit 1f854ee

77 files changed

Lines changed: 2072 additions & 357 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.

Doc/c-api/code.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ bound into a function.
2222
.. c:var:: PyTypeObject PyCode_Type
2323
2424
This is an instance of :c:type:`PyTypeObject` representing the Python
25-
:class:`code` type.
25+
:ref:`code object <code-objects>`.
2626

2727

2828
.. c:function:: int PyCode_Check(PyObject *co)
2929
30-
Return true if *co* is a :class:`code` object. This function always succeeds.
30+
Return true if *co* is a :ref:`code object <code-objects>`.
31+
This function always succeeds.
3132
3233
.. c:function:: int PyCode_GetNumFree(PyCodeObject *co)
3334

Doc/library/enum.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ Data Types
286286
appropriate value will be chosen for you. See :class:`auto` for the
287287
details.
288288

289+
.. attribute:: Enum._name_
290+
291+
Name of the member.
292+
293+
.. attribute:: Enum._value_
294+
295+
Value of the member, can be set in :meth:`~object.__new__`.
296+
297+
.. attribute:: Enum._order_
298+
299+
No longer used, kept for backward compatibility.
300+
(class attribute, removed during class creation).
301+
289302
.. attribute:: Enum._ignore_
290303

291304
``_ignore_`` is only used during creation and is removed from the
@@ -823,8 +836,8 @@ Supported ``_sunder_`` names
823836
- :attr:`~Enum._ignore_` -- a list of names, either as a :class:`list` or a
824837
:class:`str`, that will not be transformed into members, and will be removed
825838
from the final class
826-
- :attr:`~Enum._order_` -- used in Python 2/3 code to ensure member order is
827-
consistent (class attribute, removed during class creation)
839+
- :attr:`~Enum._order_` -- no longer used, kept for backward
840+
compatibility (class attribute, removed during class creation)
828841
- :meth:`~Enum._generate_next_value_` -- used to get an appropriate value for
829842
an enum member; may be overridden
830843

Doc/library/queue.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ The :mod:`queue` module defines the following classes and exceptions:
9393
on a :class:`Queue` object which is full.
9494

9595

96+
.. exception:: ShutDown
97+
98+
Exception raised when :meth:`~Queue.put` or :meth:`~Queue.get` is called on
99+
a :class:`Queue` object which has been shut down.
100+
101+
.. versionadded:: 3.13
102+
103+
96104
.. _queueobjects:
97105

98106
Queue Objects
@@ -135,6 +143,8 @@ provide the public methods described below.
135143
immediately available, else raise the :exc:`Full` exception (*timeout* is
136144
ignored in that case).
137145

146+
Raises :exc:`ShutDown` if the queue has been shut down.
147+
138148

139149
.. method:: Queue.put_nowait(item)
140150

@@ -155,6 +165,9 @@ provide the public methods described below.
155165
an uninterruptible wait on an underlying lock. This means that no exceptions
156166
can occur, and in particular a SIGINT will not trigger a :exc:`KeyboardInterrupt`.
157167

168+
Raises :exc:`ShutDown` if the queue has been shut down and is empty, or if
169+
the queue has been shut down immediately.
170+
158171

159172
.. method:: Queue.get_nowait()
160173

@@ -177,6 +190,8 @@ fully processed by daemon consumer threads.
177190
Raises a :exc:`ValueError` if called more times than there were items placed in
178191
the queue.
179192

193+
Raises :exc:`ShutDown` if the queue has been shut down immediately.
194+
180195

181196
.. method:: Queue.join()
182197

@@ -187,6 +202,8 @@ fully processed by daemon consumer threads.
187202
indicate that the item was retrieved and all work on it is complete. When the
188203
count of unfinished tasks drops to zero, :meth:`join` unblocks.
189204

205+
Raises :exc:`ShutDown` if the queue has been shut down immediately.
206+
190207

191208
Example of how to wait for enqueued tasks to be completed::
192209

@@ -214,6 +231,27 @@ Example of how to wait for enqueued tasks to be completed::
214231
print('All work completed')
215232

216233

234+
Terminating queues
235+
^^^^^^^^^^^^^^^^^^
236+
237+
:class:`Queue` objects can be made to prevent further interaction by shutting
238+
them down.
239+
240+
.. method:: Queue.shutdown(immediate=False)
241+
242+
Shut down the queue, making :meth:`~Queue.get` and :meth:`~Queue.put` raise
243+
:exc:`ShutDown`.
244+
245+
By default, :meth:`~Queue.get` on a shut down queue will only raise once the
246+
queue is empty. Set *immediate* to true to make :meth:`~Queue.get` raise
247+
immediately instead.
248+
249+
All blocked callers of :meth:`~Queue.put` will be unblocked. If *immediate*
250+
is true, also unblock callers of :meth:`~Queue.get` and :meth:`~Queue.join`.
251+
252+
.. versionadded:: 3.13
253+
254+
217255
SimpleQueue Objects
218256
-------------------
219257

Doc/reference/datamodel.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,8 +1988,8 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances.
19881988

19891989
.. method:: object.__dir__(self)
19901990

1991-
Called when :func:`dir` is called on the object. A sequence must be
1992-
returned. :func:`dir` converts the returned sequence to a list and sorts it.
1991+
Called when :func:`dir` is called on the object. An iterable must be
1992+
returned. :func:`dir` converts the returned iterable to a list and sorts it.
19931993

19941994

19951995
Customizing module attribute access
@@ -2009,7 +2009,7 @@ not found on a module object through the normal lookup, i.e.
20092009
the module ``__dict__`` before raising an :exc:`AttributeError`. If found,
20102010
it is called with the attribute name and the result is returned.
20112011

2012-
The ``__dir__`` function should accept no arguments, and return a sequence of
2012+
The ``__dir__`` function should accept no arguments, and return an iterable of
20132013
strings that represents the names accessible on module. If present, this
20142014
function overrides the standard :func:`dir` search on a module.
20152015

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Doc/library/email.compat32-message.rst
3131
Doc/library/email.errors.rst
3232
Doc/library/email.parser.rst
3333
Doc/library/email.policy.rst
34-
Doc/library/enum.rst
3534
Doc/library/exceptions.rst
3635
Doc/library/faulthandler.rst
3736
Doc/library/fcntl.rst

Doc/whatsnew/3.13.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ Improved Error Messages
101101
variables. See also :ref:`using-on-controlling-color`.
102102
(Contributed by Pablo Galindo Salgado in :gh:`112730`.)
103103

104+
* When an incorrect keyword argument is passed to a function, the error message
105+
now potentially suggests the correct keyword argument.
106+
(Contributed by Pablo Galindo Salgado and Shantanu Jain in :gh:`107944`.)
107+
108+
>>> "better error messages!".split(max_split=1)
109+
Traceback (most recent call last):
110+
File "<stdin>", line 1, in <module>
111+
"better error messages!".split(max_split=1)
112+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
113+
TypeError: split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'?
114+
104115
Other Language Changes
105116
======================
106117

@@ -392,6 +403,13 @@ pdb
392403
command line option or :envvar:`PYTHONSAFEPATH` environment variable).
393404
(Contributed by Tian Gao and Christian Walther in :gh:`111762`.)
394405

406+
queue
407+
-----
408+
409+
* Add :meth:`queue.Queue.shutdown` (along with :exc:`queue.ShutDown`) for queue
410+
termination.
411+
(Contributed by Laurie Opperman and Yves Duprat in :gh:`104750`.)
412+
395413
re
396414
--
397415
* Rename :exc:`!re.error` to :exc:`re.PatternError` for improved clarity.
@@ -1328,6 +1346,12 @@ Build Changes
13281346
:ref:`limited C API <limited-c-api>`.
13291347
(Contributed by Victor Stinner in :gh:`85283`.)
13301348

1349+
* ``wasm32-wasi`` is now a tier 2 platform.
1350+
(Contributed by Brett Cannon in :gh:`115192`.)
1351+
1352+
* ``wasm32-emscripten`` is no longer a supported platform.
1353+
(Contributed by Brett Cannon in :gh:`115192`.)
1354+
13311355

13321356
C API Changes
13331357
=============

Include/internal/pycore_brc.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef Py_INTERNAL_BRC_H
2+
#define Py_INTERNAL_BRC_H
3+
4+
#include <stdint.h>
5+
#include "pycore_llist.h" // struct llist_node
6+
#include "pycore_lock.h" // PyMutex
7+
#include "pycore_object_stack.h" // _PyObjectStack
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
#ifndef Py_BUILD_CORE
14+
# error "this header requires Py_BUILD_CORE define"
15+
#endif
16+
17+
#ifdef Py_GIL_DISABLED
18+
19+
// Prime number to avoid correlations with memory addresses.
20+
#define _Py_BRC_NUM_BUCKETS 257
21+
22+
// Hash table bucket
23+
struct _brc_bucket {
24+
// Mutex protects both the bucket and thread state queues in this bucket.
25+
PyMutex mutex;
26+
27+
// Linked list of _PyThreadStateImpl objects hashed to this bucket.
28+
struct llist_node root;
29+
};
30+
31+
// Per-interpreter biased reference counting state
32+
struct _brc_state {
33+
// Hash table of thread states by thread-id. Thread states within a bucket
34+
// are chained using a doubly-linked list.
35+
struct _brc_bucket table[_Py_BRC_NUM_BUCKETS];
36+
};
37+
38+
// Per-thread biased reference counting state
39+
struct _brc_thread_state {
40+
// Linked-list of thread states per hash bucket
41+
struct llist_node bucket_node;
42+
43+
// Thread-id as determined by _PyThread_Id()
44+
uintptr_t tid;
45+
46+
// Objects with refcounts to be merged (protected by bucket mutex)
47+
_PyObjectStack objects_to_merge;
48+
49+
// Local stack of objects to be merged (not accessed by other threads)
50+
_PyObjectStack local_objects_to_merge;
51+
};
52+
53+
// Initialize/finalize the per-thread biased reference counting state
54+
void _Py_brc_init_thread(PyThreadState *tstate);
55+
void _Py_brc_remove_thread(PyThreadState *tstate);
56+
57+
// Initialize per-interpreter state
58+
void _Py_brc_init_state(PyInterpreterState *interp);
59+
60+
void _Py_brc_after_fork(PyInterpreterState *interp);
61+
62+
// Enqueues an object to be merged by it's owning thread (tid). This
63+
// steals a reference to the object.
64+
void _Py_brc_queue_object(PyObject *ob);
65+
66+
// Merge the refcounts of queued objects for the current thread.
67+
void _Py_brc_merge_refcounts(PyThreadState *tstate);
68+
69+
#endif /* Py_GIL_DISABLED */
70+
71+
#ifdef __cplusplus
72+
}
73+
#endif
74+
#endif /* !Py_INTERNAL_BRC_H */

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ void _PyEval_FrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame)
206206
#define _PY_ASYNC_EXCEPTION_BIT 3
207207
#define _PY_GC_SCHEDULED_BIT 4
208208
#define _PY_EVAL_PLEASE_STOP_BIT 5
209+
#define _PY_EVAL_EXPLICIT_MERGE_BIT 6
209210

210211
/* Reserve a few bits for future use */
211212
#define _PY_EVAL_EVENTS_BITS 8

Include/internal/pycore_context.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ extern PyTypeObject _PyContextTokenMissing_Type;
1414
/* runtime lifecycle */
1515

1616
PyStatus _PyContext_Init(PyInterpreterState *);
17-
void _PyContext_Fini(_PyFreeListState *);
1817

1918

2019
/* other API */

Include/internal/pycore_floatobject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ extern "C" {
1515

1616
extern void _PyFloat_InitState(PyInterpreterState *);
1717
extern PyStatus _PyFloat_InitTypes(PyInterpreterState *);
18-
extern void _PyFloat_Fini(_PyFreeListState *);
1918
extern void _PyFloat_FiniType(PyInterpreterState *);
2019

2120

0 commit comments

Comments
 (0)