Special handling is needed, because for non-slots dataclasses the instance attributes are not set: reading from a field just references the class's attribute of the same name, which contains the default value. But this doesn't work for classes using __slots__: they don't read the class's attribute. So in that case (and that case only), initialize the instance attribute. Handle this for both normal defaults, and for fields using default_factory.
(cherry picked from commit d3062f672c)
Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
Suggested by Stefan Pochmann.
(cherry picked from commit 48744db70e)
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
staticmethod() also became callable in Python 3.10.
See: b83861f02.
(cherry picked from commit e34809e1c2)
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
The documentation explaining Python's data model does not adequately explain
the differences between ``__getitem__`` and ``__class_getitem__``, nor does it
explain when each is called. There is an attempt at explaining
``__class_getitem__`` in the documentation for ``GenericAlias`` objects, but
this does not give sufficient clarity into how the method works. Moreover, it
is the wrong place for that information to be found; the explanation of
``__class_getitem__`` should be in the documentation explaining the data model.
This PR has been split off from GH-29335.
(cherry picked from commit 31b3a70edb)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Some of the tests in test_queue had a race condition in which a
non-sentinel value could be enqueued after the final sentinel value
leading to not all the inputs being processed (and test failures).
This changes feed() to enqueue a sentinel once the inputs are exhausted,
which guarantees that the final queued object is a sentinel. This
requires the number of feeder threads to match the number of consumer
threads, but that's already the case in the relevant tests.
(cherry picked from commit df3e53d86b)
Co-authored-by: Sam Gross <colesbury@gmail.com>
Accessing one enum member from another originally raised an `AttributeError`, but became possible due to a performance boost implementation detail. In 3.11 it will again raise an `AttributeError`.
If the string is ASCII only and doesn't need to escape characters,
write the whole string with a single write() syscall.
(cherry picked from commit b919d8105c)
Co-authored-by: Victor Stinner <vstinner@python.org>
Unlike the other locks reinitialized by _PyRuntimeState_ReInitThreads,
the "interpreters.main->id_mutex" is not freed by _PyRuntimeState_Fini
and should not force the default raw allocator.
(cherry picked from commit 736684b1bb)
Co-authored-by: Sam Gross <colesbury@gmail.com>
I was reading this bit last night and thought it was a typo. In the light of day, I realized it wasn't *technically* a typo, but definitely confusing wording. This PR fixes the confusing sentence.
Automerge-Triggered-By: GH:ericvsmith
(cherry picked from commit f8da00ef04)
Co-authored-by: Jack DeVries <jdevries3133@gmail.com>
* [bpo-45772](): socket.socket should be a class instead of a function
Currently `socket.socket` is documented as a function, but it is really
a class (and thus has function-like usage to construct an object). This
correction would ensure that Python projects that are interlinking
Python's documentation can properly locate `socket.socket` as a type.
(cherry picked from commit 4c792f39e6)
Co-authored-by: Hong Xu <hong@topbug.net>
Automerge-Triggered-By: GH:asvetlov
Since `.. module:: contextvars` sets the module using `.. class:: contextvars.Token`, intersphinx records it as `contextvars.contextvars.Token`.
(cherry picked from commit e501d70b34)
Co-authored-by: Hynek Schlawack <hs@ox.cx>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
The PyType_HasFeature() change has been reverted: the static inline
function access directly the PyTypeObject.tp_flags member.
(cherry picked from commit 99c7e9853f)
Co-authored-by: Victor Stinner <vstinner@python.org>