Skip to content

Commit f483702

Browse files
Merge branch 'main' into gh-159689-processpool-mid-send
2 parents e4b2760 + 0d35e3b commit f483702

100 files changed

Lines changed: 2343 additions & 437 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/library/ast.rst‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ Node classes
4848
module and re-exported in :mod:`!ast`.
4949

5050
There is one class defined for each left-hand side symbol in the abstract
51-
grammar (for example, :class:`ast.stmt` or :class:`ast.expr`). In addition,
51+
grammar (for example, :class:`!ast.stmt` or :class:`!ast.expr`). In addition,
5252
there is one class defined for each constructor on the right-hand side; these
5353
classes inherit from the classes for the left-hand side trees. For example,
54-
:class:`ast.BinOp` inherits from :class:`ast.expr`. For production rules
54+
:class:`ast.BinOp` inherits from :class:`!ast.expr`. For production rules
5555
with alternatives (aka "sums"), the left-hand side class is abstract: only
5656
instances of specific constructor nodes are ever created.
5757

@@ -65,7 +65,7 @@ Node classes
6565

6666
Each instance of a concrete class has one attribute for each child node,
6767
of the type as defined in the grammar. For example, :class:`ast.BinOp`
68-
instances have an attribute :attr:`left` of type :class:`ast.expr`.
68+
instances have an attribute :attr:`!left` of type :class:`!ast.expr`.
6969

7070
If these attributes are marked as optional in the grammar (using a
7171
question mark), the value might be ``None``. If the attributes can have
@@ -104,10 +104,11 @@ Node classes
104104
one can get the source segment of a one-line expression node using
105105
``source_line[node.col_offset : node.end_col_offset]``.
106106

107-
The constructor of a class :class:`ast.T` parses its arguments as follows:
107+
The constructors of AST node classes parse their arguments as follows:
108108

109109
* If there are positional arguments, there must be as many as there are items
110-
in :attr:`T._fields`; they will be assigned as attributes of these names.
110+
in :attr:`!_fields`; they will be assigned to attributes with
111+
the corresponding names.
111112
* If there are keyword arguments, they will set the attributes of the same
112113
names to the given values.
113114

@@ -2223,8 +2224,8 @@ Async and await
22232224

22242225
.. note::
22252226
When a string is parsed by :func:`ast.parse`, operator nodes (subclasses
2226-
of :class:`ast.operator`, :class:`ast.unaryop`, :class:`ast.cmpop`,
2227-
:class:`ast.boolop` and :class:`ast.expr_context`) on the returned tree
2227+
of :class:`!ast.operator`, :class:`!ast.unaryop`, :class:`!ast.cmpop`,
2228+
:class:`!ast.boolop` and :class:`!ast.expr_context`) on the returned tree
22282229
will be singletons. Changes to one will be reflected in all other
22292230
occurrences of the same value (for example, :class:`ast.Add`).
22302231

‎Doc/library/datetime.rst‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2699,6 +2699,10 @@ convenience.
26992699
| | number, zero-padded to 6 | 999999 | |
27002700
| | digits. | | |
27012701
+-----------+--------------------------------+------------------------+-------+
2702+
| ``%Nf`` | Fraction of a second truncated | 000, 001, ..., 999 | \(5) |
2703+
| | to *N* digits, where *N* is | (``%3f``) | |
2704+
| | from 1 to 6. | | |
2705+
+-----------+--------------------------------+------------------------+-------+
27022706
| ``%:z`` | UTC offset in the form | (empty), +00:00, | \(6) |
27032707
| | ``±HH:MM[:SS[.ffffff]]`` | -04:00, +10:30, | |
27042708
| | (empty string if the object is | +06:34:15, | |
@@ -2721,6 +2725,9 @@ differences between platforms in handling of unsupported format specifiers.
27212725
``%D``, ``%F``, ``%n``, ``%t``, and ``%:z`` were added for
27222726
:meth:`~.datetime.strptime`.
27232727

2728+
.. versionadded:: next
2729+
``%Nf`` was added.
2730+
27242731

27252732
Technical detail
27262733
^^^^^^^^^^^^^^^^
@@ -2833,7 +2840,8 @@ Notes:
28332840

28342841
(5)
28352842
When used with the :meth:`~.datetime.strptime` method, the ``%f`` directive
2836-
accepts from one to six digits and zero pads on the right. ``%f`` is
2843+
accepts from one to six digits and zero pads on the right, while ``%Nf``
2844+
accepts exactly *N* digits. ``%f`` is
28372845
an extension to the set of format characters in the C standard (but
28382846
implemented separately in datetime objects, and therefore always
28392847
available).

‎Doc/library/pickle.rst‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,11 @@ The following types can be pickled:
517517
* classes accessible from the top level of a module;
518518

519519
* instances of such classes for which the result of calling :meth:`~object.__getstate__`
520-
is picklable (see section :ref:`pickle-inst` for details).
520+
is picklable (see section :ref:`pickle-inst` for details);
521+
522+
* weak references and the weak containers from the :mod:`weakref` module,
523+
provided that the weakly referenced objects are strongly referenced
524+
elsewhere in the same pickle (see :class:`weakref.ref`).
521525

522526
Attempts to pickle unpicklable objects will raise the :exc:`PicklingError`
523527
exception; when this happens, an unspecified number of bytes may have already

‎Doc/library/weakref.rst‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ See :ref:`__slots__ documentation <slots>` for details.
126126
Weak references are :ref:`generic <generics>` over the type of the object they
127127
reference.
128128

129+
A weak reference can be pickled
130+
if the referent is strongly referenced elsewhere in the same pickle;
131+
otherwise pickling raises :exc:`pickle.PicklingError`.
132+
The unpickled weak reference refers to the unpickled referent.
133+
A reference to a dead object unpickles as a reference to a dead object.
134+
The *callback* is not preserved.
135+
136+
Weak references are atomic for the :mod:`copy` module:
137+
:func:`copy.copy` and :func:`copy.deepcopy` return
138+
the original weak reference without copying the referent.
139+
129140
.. attribute:: __callback__
130141

131142
This read-only attribute returns the callback currently associated to the
@@ -138,6 +149,9 @@ See :ref:`__slots__ documentation <slots>` for details.
138149
.. versionchanged:: 3.16
139150
Raise :exc:`!TypeError` if *callback* is not callable or ``None``.
140151

152+
.. versionchanged:: next
153+
Weak references can now be pickled.
154+
141155

142156
.. function:: proxy(object[, callback])
143157

@@ -203,9 +217,16 @@ See :ref:`__slots__ documentation <slots>` for details.
203217
>>> d[k2] = 2 # d = {k2: 2}
204218
>>> del k1 # d = {k2: 2}
205219

220+
A :class:`!WeakKeyDictionary` can be copied,
221+
and pickled if the keys are strongly referenced
222+
elsewhere in the same pickle (see :class:`ref`).
223+
206224
.. versionchanged:: 3.9
207225
Added support for ``|`` and ``|=`` operators, as specified in :pep:`584`.
208226

227+
.. versionchanged:: next
228+
:class:`!WeakKeyDictionary` can now be pickled.
229+
209230
:class:`WeakKeyDictionary` objects have an additional method that
210231
exposes the internal references directly. The references are not guaranteed to
211232
be "live" at the time they are used, so the result of calling the references
@@ -224,9 +245,16 @@ than needed.
224245
Mapping class that references values weakly. Entries in the dictionary will be
225246
discarded when no strong reference to the value exists any more.
226247

248+
A :class:`!WeakValueDictionary` can be copied,
249+
and pickled if the values are strongly referenced
250+
elsewhere in the same pickle (see :class:`ref`).
251+
227252
.. versionchanged:: 3.9
228253
Added support for ``|`` and ``|=`` operators, as specified in :pep:`584`.
229254

255+
.. versionchanged:: next
256+
:class:`!WeakValueDictionary` can now be pickled.
257+
230258
:class:`WeakValueDictionary` objects have the following additional methods.
231259
These have the same issues as the :meth:`WeakKeyDictionary.keyrefs` method.
232260

@@ -246,6 +274,14 @@ These have the same issues as the :meth:`WeakKeyDictionary.keyrefs` method.
246274
Set class that keeps weak references to its elements. An element will be
247275
discarded when no strong reference to it exists any more.
248276

277+
A :class:`!WeakSet` can be pickled if the elements are strongly
278+
referenced elsewhere in the same pickle (see :class:`ref`).
279+
A copy or a deep copy shares the elements with the original;
280+
user-defined attributes are copied or deep-copied.
281+
282+
.. versionchanged:: next
283+
:class:`!WeakSet` can now be pickled and copied.
284+
249285

250286
.. class:: WeakMethod(method[, callback])
251287

@@ -275,8 +311,16 @@ These have the same issues as the :meth:`WeakKeyDictionary.keyrefs` method.
275311

276312
*callback* is the same as the parameter of the same name to the :func:`ref` function.
277313

314+
A :class:`!WeakMethod` can be copied,
315+
and pickled if the object the method is bound to is strongly referenced
316+
elsewhere in the same pickle (see :class:`ref`).
317+
A copy or a deep copy is an equal weak method to the same object.
318+
278319
.. versionadded:: 3.4
279320

321+
.. versionchanged:: next
322+
:class:`!WeakMethod` can now be pickled and copied.
323+
280324
.. class:: finalize(obj, func, /, *args, **kwargs)
281325

282326
Return a callable finalizer object which will be called when *obj*

‎Doc/library/zlib.rst‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,14 @@ the following constants:
487487

488488
The version string of the zlib library actually loaded by the interpreter.
489489

490+
Prefer :const:`!zlib_version` over its :const:`!ZLIB_RUNTIME_VERSION` alias.
491+
490492
.. versionadded:: 3.3
491493
The :const:`!ZLIB_RUNTIME_VERSION` constant.
492494

493495
.. versionadded:: 3.16
494-
The :const:`!zlib_version` alias.
496+
The :const:`!zlib_version` constant; :const:`!ZLIB_RUNTIME_VERSION` is now
497+
an alias for it.
495498

496499

497500
.. data:: ZLIB_VERSION_INFO

‎Doc/whatsnew/3.16.rst‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,16 @@ curses
362362
(Contributed by Serhiy Storchaka in :gh:`133031`.)
363363

364364

365+
datetime
366+
--------
367+
368+
* Add the ``%Nf`` format code (where *N* is from 1 to 6) to
369+
:meth:`datetime.datetime.strftime`, :meth:`datetime.time.strftime`,
370+
:meth:`datetime.date.strftime`, :meth:`datetime.datetime.strptime` and
371+
:meth:`datetime.time.strptime`.
372+
(Contributed by Stan Ulbrych and Karoline Pauls in :gh:`157290`.)
373+
374+
365375
dbm.gnu
366376
-------
367377

@@ -576,6 +586,17 @@ pydoc
576586
(Contributed by Serhiy Storchaka in :gh:`153906`.)
577587

578588

589+
pickle
590+
------
591+
592+
* Weak references (:class:`weakref.ref`), :class:`weakref.WeakMethod`,
593+
:class:`weakref.WeakSet`, :class:`weakref.WeakValueDictionary` and
594+
:class:`weakref.WeakKeyDictionary` can now be pickled if the weakly
595+
referenced objects are strongly referenced elsewhere in the same pickle;
596+
otherwise pickling raises :exc:`pickle.PicklingError`.
597+
:class:`!WeakMethod` and :class:`!WeakSet` can now also be copied.
598+
(Contributed by Serhiy Storchaka in :gh:`74876`.)
599+
579600
re
580601
--
581602

‎Include/internal/pycore_qsbr.h‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,25 @@ struct _qsbr_thread_state {
6969
struct _qsbr_thread_state *freelist_next;
7070
};
7171

72+
// Size used to pad and align the per-thread QSBR states (and the end of
73+
// _PyThreadStateImpl) to avoid false sharing. Apple Silicon has 128-byte cache
74+
// lines:
75+
// $ sysctl -a hw | grep cachelinesize
76+
// hw.cachelinesize: 128
77+
// With 64-byte padding the `seq` fields of two threads share a line and the
78+
// stores in _Py_qsbr_quiescent_state() contend on every eval loop back-edge.
79+
// Use 128 bytes for all AArch64 targets: on cores with 64-byte lines this only
80+
// costs 64 bytes per thread.
81+
#if defined(__aarch64__) || defined(_M_ARM64)
82+
# define _Py_QSBR_CACHE_LINE_SIZE 128
83+
#else
84+
# define _Py_QSBR_CACHE_LINE_SIZE 64
85+
#endif
86+
7287
// Padding to avoid false sharing
7388
struct _qsbr_pad {
7489
struct _qsbr_thread_state qsbr;
75-
char __padding[64 - sizeof(struct _qsbr_thread_state)];
90+
char __padding[_Py_QSBR_CACHE_LINE_SIZE - sizeof(struct _qsbr_thread_state)];
7691
};
7792

7893
// Per-interpreter state
@@ -83,7 +98,7 @@ struct _qsbr_shared {
8398
// Minimum observed read sequence of all QSBR thread states
8499
uint64_t rd_seq;
85100

86-
// Array of QSBR thread states (aligned to 64 bytes).
101+
// Array of QSBR thread states (aligned to _Py_QSBR_CACHE_LINE_SIZE).
87102
struct _qsbr_pad *array;
88103
void *array_raw; // raw allocation pointer (for free)
89104
Py_ssize_t size;

‎Include/internal/pycore_tstate.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ typedef struct _PyThreadStateImpl {
109109
#ifdef Py_GIL_DISABLED
110110
// gh-144438: Add padding to ensure that the fields above don't share a
111111
// cache line with other allocations.
112-
char __padding[64];
112+
char __padding[_Py_QSBR_CACHE_LINE_SIZE];
113113
#endif
114114
} _PyThreadStateImpl;
115115

‎Lib/_pydatetime.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ def _wrap_strftime(object, format, timetuple):
237237
freplace = '%06d' % getattr(object,
238238
'microsecond', 0)
239239
newformat.append(freplace)
240+
elif ch in '123456' and format[i:i+1] == 'f':
241+
i += 1
242+
if freplace is None:
243+
freplace = '%06d' % getattr(object,
244+
'microsecond', 0)
245+
precision = int(ch)
246+
newformat.append(freplace[:precision])
240247
elif ch == 'z':
241248
if zreplace is None:
242249
if hasattr(object, "utcoffset"):

0 commit comments

Comments
 (0)