Merge remote-tracking branch 'upstream/main' into asyncio_rest_thread… · python/cpython@b450b96 · GitHub
Skip to content

Commit b450b96

Browse files
Merge remote-tracking branch 'upstream/main' into asyncio_rest_threadsafe
2 parents c9ac6bb + 5d6861a commit b450b96

67 files changed

Lines changed: 735 additions & 270 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.

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion

Doc/c-api/module.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ state:
517517
518518
On success, return ``0``. On error, raise an exception and return ``-1``.
519519
520-
Return ``NULL`` if *value* is ``NULL``. It must be called with an exception
520+
Return ``-1`` if *value* is ``NULL``. It must be called with an exception
521521
raised in this case.
522522
523523
Example usage::

Doc/faq/programming.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,11 +1741,31 @@ but effective way to define class private variables. Any identifier of the form
17411741
is textually replaced with ``_classname__spam``, where ``classname`` is the
17421742
current class name with any leading underscores stripped.
17431743

1744-
This doesn't guarantee privacy: an outside user can still deliberately access
1745-
the "_classname__spam" attribute, and private values are visible in the object's
1746-
``__dict__``. Many Python programmers never bother to use private variable
1747-
names at all.
1744+
The identifier can be used unchanged within the class, but to access it outside
1745+
the class, the mangled name must be used:
17481746

1747+
.. code-block:: python
1748+
1749+
class A:
1750+
def __one(self):
1751+
return 1
1752+
def two(self):
1753+
return 2 * self.__one()
1754+
1755+
class B(A):
1756+
def three(self):
1757+
return 3 * self._A__one()
1758+
1759+
four = 4 * A()._A__one()
1760+
1761+
In particular, this does not guarantee privacy since an outside user can still
1762+
deliberately access the private attribute; many Python programmers never bother
1763+
to use private variable names at all.
1764+
1765+
.. seealso::
1766+
1767+
The :ref:`private name mangling specifications <private-name-mangling>`
1768+
for details and special cases.
17491769

17501770
My class defines __del__ but it is not called when I delete the object.
17511771
-----------------------------------------------------------------------

Doc/library/configparser.rst

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,28 @@ case-insensitive and stored in lowercase [1]_.
147147
It is possible to read several configurations into a single
148148
:class:`ConfigParser`, where the most recently added configuration has the
149149
highest priority. Any conflicting keys are taken from the more recent
150-
configuration while the previously existing keys are retained.
150+
configuration while the previously existing keys are retained. The example
151+
below reads in an ``override.ini`` file, which will override any conflicting
152+
keys from the ``example.ini`` file.
153+
154+
.. code-block:: ini
155+
156+
[DEFAULT]
157+
ServerAliveInterval = -1
151158
152159
.. doctest::
153160

154-
>>> another_config = configparser.ConfigParser()
155-
>>> another_config.read('example.ini')
156-
['example.ini']
157-
>>> another_config['topsecret.server.example']['Port']
158-
'50022'
159-
>>> another_config.read_string("[topsecret.server.example]\nPort=48484")
160-
>>> another_config['topsecret.server.example']['Port']
161-
'48484'
162-
>>> another_config.read_dict({"topsecret.server.example": {"Port": 21212}})
163-
>>> another_config['topsecret.server.example']['Port']
164-
'21212'
165-
>>> another_config['topsecret.server.example']['ForwardX11']
166-
'no'
161+
>>> config_override = configparser.ConfigParser()
162+
>>> config_override['DEFAULT'] = {'ServerAliveInterval': '-1'}
163+
>>> with open('override.ini', 'w') as configfile:
164+
... config_override.write(configfile)
165+
...
166+
>>> config_override = configparser.ConfigParser()
167+
>>> config_override.read(['example.ini', 'override.ini'])
168+
['example.ini', 'override.ini']
169+
>>> print(config_override.get('DEFAULT', 'ServerAliveInterval'))
170+
-1
171+
167172

168173
This behaviour is equivalent to a :meth:`ConfigParser.read` call with several
169174
files passed to the *filenames* parameter.
@@ -984,6 +989,31 @@ ConfigParser Objects
984989
converter gets its own corresponding :meth:`!get*()` method on the parser
985990
object and section proxies.
986991

992+
It is possible to read several configurations into a single
993+
:class:`ConfigParser`, where the most recently added configuration has the
994+
highest priority. Any conflicting keys are taken from the more recent
995+
configuration while the previously existing keys are retained. The example
996+
below reads in an ``override.ini`` file, which will override any conflicting
997+
keys from the ``example.ini`` file.
998+
999+
.. code-block:: ini
1000+
1001+
[DEFAULT]
1002+
ServerAliveInterval = -1
1003+
1004+
.. doctest::
1005+
1006+
>>> config_override = configparser.ConfigParser()
1007+
>>> config_override['DEFAULT'] = {'ServerAliveInterval': '-1'}
1008+
>>> with open('override.ini', 'w') as configfile:
1009+
... config_override.write(configfile)
1010+
...
1011+
>>> config_override = configparser.ConfigParser()
1012+
>>> config_override.read(['example.ini', 'override.ini'])
1013+
['example.ini', 'override.ini']
1014+
>>> print(config_override.get('DEFAULT', 'ServerAliveInterval'))
1015+
-1
1016+
9871017
.. versionchanged:: 3.1
9881018
The default *dict_type* is :class:`collections.OrderedDict`.
9891019

Doc/library/ftplib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ FTP objects
243243
Retrieve a file in binary transfer mode.
244244

245245
:param str cmd:
246-
An appropriate ``STOR`` command: :samp:`"STOR {filename}"`.
246+
An appropriate ``RETR`` command: :samp:`"RETR {filename}"`.
247247

248248
:param callback:
249249
A single parameter callable that is called

Doc/library/multiprocessing.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ processes:
254254
p.join()
255255

256256
Queues are thread and process safe.
257+
Any object put into a :mod:`~multiprocessing` queue will be serialized.
257258

258259
**Pipes**
259260

@@ -281,6 +282,8 @@ processes:
281282
of corruption from processes using different ends of the pipe at the same
282283
time.
283284

285+
The :meth:`~Connection.send` method serializes the the object and
286+
:meth:`~Connection.recv` re-creates the object.
284287

285288
Synchronization between processes
286289
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -745,6 +748,11 @@ If you use :class:`JoinableQueue` then you **must** call
745748
semaphore used to count the number of unfinished tasks may eventually overflow,
746749
raising an exception.
747750

751+
One difference from other Python queue implementations, is that :mod:`multiprocessing`
752+
queues serializes all objects that are put into them using :mod:`pickle`.
753+
The object return by the get method is a re-created object that does not share memory
754+
with the original object.
755+
748756
Note that one can also create a shared queue by using a manager object -- see
749757
:ref:`multiprocessing-managers`.
750758

@@ -811,6 +819,8 @@ For an example of the usage of queues for interprocess communication see
811819
used for receiving messages and ``conn2`` can only be used for sending
812820
messages.
813821

822+
The :meth:`~multiprocessing.Connection.send` method serializes the the object using
823+
:mod:`pickle` and the :meth:`~multiprocessing.Connection.recv` re-creates the object.
814824

815825
.. class:: Queue([maxsize])
816826

Doc/library/unittest.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,8 @@ Loading and running tests
23162316
(see :ref:`Warning control <using-on-warnings>`),
23172317
otherwise it will be set to ``'default'``.
23182318

2319-
Calling ``main`` actually returns an instance of the ``TestProgram`` class.
2320-
This stores the result of the tests run as the ``result`` attribute.
2319+
Calling ``main`` returns an object with the ``result`` attribute that contains
2320+
the result of the tests run as a :class:`unittest.TestResult`.
23212321

23222322
.. versionchanged:: 3.1
23232323
The *exit* parameter was added.

Doc/reference/expressions.rst

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,47 @@ exception.
8383
pair: name; mangling
8484
pair: private; names
8585

86-
**Private name mangling:** When an identifier that textually occurs in a class
87-
definition begins with two or more underscore characters and does not end in two
88-
or more underscores, it is considered a :dfn:`private name` of that class.
89-
Private names are transformed to a longer form before code is generated for
90-
them. The transformation inserts the class name, with leading underscores
91-
removed and a single underscore inserted, in front of the name. For example,
92-
the identifier ``__spam`` occurring in a class named ``Ham`` will be transformed
93-
to ``_Ham__spam``. This transformation is independent of the syntactical
94-
context in which the identifier is used. If the transformed name is extremely
95-
long (longer than 255 characters), implementation defined truncation may happen.
96-
If the class name consists only of underscores, no transformation is done.
86+
Private name mangling
87+
^^^^^^^^^^^^^^^^^^^^^
9788

89+
When an identifier that textually occurs in a class definition begins with two
90+
or more underscore characters and does not end in two or more underscores, it
91+
is considered a :dfn:`private name` of that class.
92+
93+
.. seealso::
94+
95+
The :ref:`class specifications <class>`.
96+
97+
More precisely, private names are transformed to a longer form before code is
98+
generated for them. If the transformed name is longer than 255 characters,
99+
implementation-defined truncation may happen.
100+
101+
The transformation is independent of the syntactical context in which the
102+
identifier is used but only the following private identifiers are mangled:
103+
104+
- Any name used as the name of a variable that is assigned or read or any
105+
name of an attribute being accessed.
106+
107+
The ``__name__`` attribute of nested functions, classes, and type aliases
108+
is however not mangled.
109+
110+
- The name of imported modules, e.g., ``__spam`` in ``import __spam``.
111+
If the module is part of a package (i.e., its name contains a dot),
112+
the name is *not* mangled, e.g., the ``__foo`` in ``import __foo.bar``
113+
is not mangled.
114+
115+
- The name of an imported member, e.g., ``__f`` in ``from spam import __f``.
116+
117+
The transformation rule is defined as follows:
118+
119+
- The class name, with leading underscores removed and a single leading
120+
underscore inserted, is inserted in front of the identifier, e.g., the
121+
identifier ``__spam`` occurring in a class named ``Foo``, ``_Foo`` or
122+
``__Foo`` is transformed to ``_Foo__spam``.
123+
124+
- If the class name consists only of underscores, the transformation is the
125+
identity, e.g., the identifier ``__spam`` occurring in a class named ``_``
126+
or ``__`` is left as is.
98127

99128
.. _atom-literals:
100129

Doc/tutorial/classes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,11 @@ current class name with leading underscore(s) stripped. This mangling is done
688688
without regard to the syntactic position of the identifier, as long as it
689689
occurs within the definition of a class.
690690

691+
.. seealso::
692+
693+
The :ref:`private name mangling specifications <private-name-mangling>`
694+
for details and special cases.
695+
691696
Name mangling is helpful for letting subclasses override methods without
692697
breaking intraclass method calls. For example::
693698

Include/cpython/code.h

Lines changed: 0 additions & 3 deletions

0 commit comments

Comments
 (0)