Skip to content

Commit a69eef8

Browse files
committed
Merge remote-tracking branch 'origin/master' into bpo_39337_new_2
* origin/master: (147 commits) Fix the attribute names in the docstring of GenericAlias (pythonGH-22594) bpo-39337: Add a test case for normalizing of codec names (pythonGH-19069) bpo-41557: Update Windows installer to use SQLite 3.33.0 (pythonGH-21960) bpo-41976: Fix the fallback to gcc of ctypes.util.find_library when using gcc>9 (pythonGH-22598) bpo-41306: Allow scale value to not be rounded (pythonGH-21715) bpo-41970: Avoid test failure in test_lib2to3 if the module is already imported (pythonGH-22595) bpo-41376: Fix the documentation of `site.getusersitepackages()` (pythonGH-21602) Revert "bpo-26680: Incorporate is_integer in all built-in and standard library numeric types (pythonGH-6121)" (pythonGH-22584) bpo-41923: PEP 613: Add TypeAlias to typing module (python#22532) Fix comment about PyObject_IsTrue. (pythonGH-22343) bpo-38605: Make 'from __future__ import annotations' the default (pythonGH-20434) bpo-41905: Add abc.update_abstractmethods() (pythonGH-22485) bpo-41944: No longer call eval() on content received via HTTP in the UnicodeNames tests (pythonGH-22575) bpo-41944: No longer call eval() on content received via HTTP in the CJK codec tests (pythonGH-22566) Post 3.10.0a1 Python 3.10.0a1 bpo-41584: clarify when the reflected method of a binary arithemtic operator is called (python#22505) bpo-41939: Fix test_site.test_license_exists_at_url() (python#22559) bpo-41774: Tweak new programming FAQ entry (pythonGH-22562) bpo-41936. Remove macros Py_ALLOW_RECURSION/Py_END_ALLOW_RECURSION (pythonGH-22552) ...
2 parents 3fa221f + 77f0a23 commit a69eef8

File tree

532 files changed

+9084
-3940
lines changed

Some content is hidden

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

532 files changed

+9084
-3940
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ matrix:
5151
env: TESTING=docs
5252
before_script:
5353
- cd Doc
54-
# Sphinx is pinned so that new versions that introduce new warnings won't suddenly cause build failures.
55-
# (Updating the version is fine as long as no warnings are raised by doing so.)
56-
# The theme used by the docs is stored separately, so we need to install that as well.
57-
- python -m pip install sphinx==2.2.0 blurb python-docs-theme
54+
- make venv PYTHON=python
5855
script:
5956
- make check suspicious html SPHINXOPTS="-q -W -j4"
6057
- name: "Documentation tests"

Doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ clean:
143143
venv:
144144
$(PYTHON) -m venv $(VENVDIR)
145145
$(VENVDIR)/bin/python3 -m pip install -U pip setuptools
146-
$(VENVDIR)/bin/python3 -m pip install -U Sphinx==3.2.1 blurb python-docs-theme
146+
$(VENVDIR)/bin/python3 -m pip install -r requirements.txt
147147
@echo "The venv has been created in the $(VENVDIR) directory"
148148

149149
dist:

Doc/c-api/codec.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ Codec registry and support functions
1010
As side effect, this tries to load the :mod:`encodings` package, if not yet
1111
done, to make sure that it is always first in the list of search functions.
1212
13+
.. c:function:: int PyCodec_Unregister(PyObject *search_function)
14+
15+
Unregister a codec search function and clear the registry's cache.
16+
If the search function is not registered, do nothing.
17+
Return 0 on success. Raise an exception and return -1 on error.
18+
19+
.. versionadded:: 3.10
20+
1321
.. c:function:: int PyCodec_KnownEncoding(const char *encoding)
1422
1523
Return ``1`` or ``0`` depending on whether there is a registered codec for

Doc/c-api/datetime.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ must not be ``NULL``, and the type is not checked:
185185
186186
Return the microsecond, as an int from 0 through 999999.
187187
188+
.. c:function:: PyObject* PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)
189+
190+
Return the tzinfo (which may be ``None``).
191+
192+
.. versionadded:: 3.10
188193
189194
Macros to extract fields from time objects. The argument must be an instance of
190195
:c:data:`PyDateTime_Time`, including subclasses. The argument must not be ``NULL``,
@@ -209,6 +214,12 @@ and the type is not checked:
209214
210215
Return the microsecond, as an int from 0 through 999999.
211216
217+
.. c:function:: PyObject* PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)
218+
219+
Return the tzinfo (which may be ``None``).
220+
221+
.. versionadded:: 3.10
222+
212223
213224
Macros to extract fields from time delta objects. The argument must be an
214225
instance of :c:data:`PyDateTime_Delta`, including subclasses. The argument must

Doc/c-api/dict.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,16 @@ Dictionary Objects
8181
.. c:function:: int PyDict_DelItem(PyObject *p, PyObject *key)
8282
8383
Remove the entry in dictionary *p* with key *key*. *key* must be hashable;
84-
if it isn't, :exc:`TypeError` is raised. Return ``0`` on success or ``-1``
85-
on failure.
84+
if it isn't, :exc:`TypeError` is raised.
85+
If *key* is not in the dictionary, :exc:`KeyError` is raised.
86+
Return ``0`` on success or ``-1`` on failure.
8687
8788
8889
.. c:function:: int PyDict_DelItemString(PyObject *p, const char *key)
8990
90-
Remove the entry in dictionary *p* which has a key specified by the string
91-
*key*. Return ``0`` on success or ``-1`` on failure.
91+
Remove the entry in dictionary *p* which has a key specified by the string *key*.
92+
If *key* is not in the dictionary, :exc:`KeyError` is raised.
93+
Return ``0`` on success or ``-1`` on failure.
9294
9395
9496
.. c:function:: PyObject* PyDict_GetItem(PyObject *p, PyObject *key)

Doc/c-api/gen.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
1515
The C structure used for generator objects.
1616

1717

18+
.. c:type:: PySendResult
19+
20+
The enum value used to represent different results of :c:func:`PyGen_Send`.
21+
22+
1823
.. c:var:: PyTypeObject PyGen_Type
1924
2025
The type object corresponding to generator objects.
@@ -42,3 +47,13 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
4247
with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
4348
A reference to *frame* is stolen by this function. The *frame* argument
4449
must not be ``NULL``.
50+
51+
.. c:function:: PySendResult PyGen_Send(PyGenObject *gen, PyObject *arg, PyObject **presult)
52+
53+
Sends the *arg* value into the generator *gen*. Coroutine objects
54+
are also allowed to be as the *gen* argument but they need to be
55+
explicitly casted to PyGenObject*. Returns:
56+
57+
- ``PYGEN_RETURN`` if generator returns. Return value is returned via *presult*.
58+
- ``PYGEN_NEXT`` if generator yields. Yielded value is returned via *presult*.
59+
- ``PYGEN_ERROR`` if generator has raised and exception. *presult* is set to ``NULL``.

Doc/data/refcounts.dat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,11 @@ PyGen_NewWithQualName:PyFrameObject*:frame:0:
959959
PyGen_NewWithQualName:PyObject*:name:0:
960960
PyGen_NewWithQualName:PyObject*:qualname:0:
961961

962+
PyGen_Send:int:::
963+
PyGen_Send:PyGenObject*:gen:0:
964+
PyGen_Send:PyObject*:arg:0:
965+
PyGen_Send:PyObject**:presult:+1:
966+
962967
PyCoro_CheckExact:int:::
963968
PyCoro_CheckExact:PyObject*:ob:0:
964969

Doc/faq/programming.rst

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,21 @@ This converts the list into a set, thereby removing duplicates, and then back
11641164
into a list.
11651165

11661166

1167+
How do you remove multiple items from a list
1168+
--------------------------------------------
1169+
1170+
As with removing duplicates, explicitly iterating in reverse with a
1171+
delete condition is one possibility. However, it is easier and faster
1172+
to use slice replacement with an implicit or explicit forward iteration.
1173+
Here are three variations.::
1174+
1175+
mylist[:] = filter(keep_function, mylist)
1176+
mylist[:] = (x for x in mylist if keep_condition)
1177+
mylist[:] = [x for x in mylist if keep_condition]
1178+
1179+
The list comprehension may be fastest.
1180+
1181+
11671182
How do you make an array in Python?
11681183
-----------------------------------
11691184

@@ -1176,7 +1191,7 @@ difference is that a Python list can contain objects of many different types.
11761191

11771192
The ``array`` module also provides methods for creating arrays of fixed types
11781193
with compact representations, but they are slower to index than lists. Also
1179-
note that the Numeric extensions and others define array-like structures with
1194+
note that NumPy and other third party packages define array-like structures with
11801195
various characteristics as well.
11811196

11821197
To get Lisp-style linked lists, you can emulate cons cells using tuples::
@@ -1504,20 +1519,19 @@ Most :meth:`__setattr__` implementations must modify ``self.__dict__`` to store
15041519
local state for self without causing an infinite recursion.
15051520

15061521

1507-
How do I call a method defined in a base class from a derived class that overrides it?
1508-
--------------------------------------------------------------------------------------
1522+
How do I call a method defined in a base class from a derived class that extends it?
1523+
------------------------------------------------------------------------------------
15091524

15101525
Use the built-in :func:`super` function::
15111526

15121527
class Derived(Base):
15131528
def meth(self):
1514-
super(Derived, self).meth()
1529+
super().meth() # calls Base.meth
15151530

1516-
For version prior to 3.0, you may be using classic classes: For a class
1517-
definition such as ``class Derived(Base): ...`` you can call method ``meth()``
1518-
defined in ``Base`` (or one of ``Base``'s base classes) as ``Base.meth(self,
1519-
arguments...)``. Here, ``Base.meth`` is an unbound method, so you need to
1520-
provide the ``self`` argument.
1531+
In the example, :func:`super` will automatically determine the instance from
1532+
which it was called (the ``self`` value), look up the :term:`method resolution
1533+
order` (MRO) with ``type(self).__mro__``, and return the next in line after
1534+
``Derived`` in the MRO: ``Base``.
15211535

15221536

15231537
How can I organize my code to make it easier to change the base class?

Doc/glossary.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,19 +1084,15 @@ Glossary
10841084
Type aliases are useful for simplifying :term:`type hints <type hint>`.
10851085
For example::
10861086

1087-
from typing import List, Tuple
1088-
10891087
def remove_gray_shades(
1090-
colors: List[Tuple[int, int, int]]) -> List[Tuple[int, int, int]]:
1088+
colors: list[tuple[int, int, int]]) -> list[tuple[int, int, int]]:
10911089
pass
10921090

10931091
could be made more readable like this::
10941092

1095-
from typing import List, Tuple
1096-
1097-
Color = Tuple[int, int, int]
1093+
Color = tuple[int, int, int]
10981094

1099-
def remove_gray_shades(colors: List[Color]) -> List[Color]:
1095+
def remove_gray_shades(colors: list[Color]) -> list[Color]:
11001096
pass
11011097

11021098
See :mod:`typing` and :pep:`484`, which describe this functionality.

Doc/library/abc.rst

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@ The :mod:`abc` module also provides the following decorator:
174174
to declare abstract methods for properties and descriptors.
175175

176176
Dynamically adding abstract methods to a class, or attempting to modify the
177-
abstraction status of a method or class once it is created, are not
178-
supported. The :func:`abstractmethod` only affects subclasses derived using
179-
regular inheritance; "virtual subclasses" registered with the ABC's
180-
:meth:`register` method are not affected.
177+
abstraction status of a method or class once it is created, are only
178+
supported using the :func:`update_abstractmethods` function. The
179+
:func:`abstractmethod` only affects subclasses derived using regular
180+
inheritance; "virtual subclasses" registered with the ABC's :meth:`register`
181+
method are not affected.
181182

182183
When :func:`abstractmethod` is applied in combination with other method
183184
descriptors, it should be applied as the innermost decorator, as shown in
@@ -235,7 +236,6 @@ The :mod:`abc` module also provides the following decorator:
235236
super-call in a framework that uses cooperative
236237
multiple-inheritance.
237238

238-
239239
The :mod:`abc` module also supports the following legacy decorators:
240240

241241
.. decorator:: abstractclassmethod
@@ -335,6 +335,22 @@ The :mod:`abc` module also provides the following functions:
335335

336336
.. versionadded:: 3.4
337337

338+
.. function:: update_abstractmethods(cls)
339+
A function to recalculate an abstract class's abstraction status. This
340+
function should be called if a class's abstract methods have been
341+
implemented or changed after it was created. Usually, this function should
342+
be called from within a class decorator.
343+
344+
Returns *cls*, to allow usage as a class decorator.
345+
346+
If *cls* is not an instance of ABCMeta, does nothing.
347+
348+
.. note::
349+
350+
This function assumes that *cls*'s superclasses are already updated.
351+
It does not update any subclasses.
352+
353+
.. versionadded:: 3.10
338354

339355
.. rubric:: Footnotes
340356

Doc/library/array.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ Examples::
257257
Packing and unpacking of External Data Representation (XDR) data as used in some
258258
remote procedure call systems.
259259

260-
`The Numerical Python Documentation <https://docs.scipy.org/doc/>`_
261-
The Numeric Python extension (NumPy) defines another array type; see
262-
http://www.numpy.org/ for further information about Numerical Python.
260+
`NumPy <https://numpy.org/>`_
261+
The NumPy package defines another array type.
263262

Doc/library/ast.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,9 @@ and classes for traversing abstract syntax trees:
15861586
.. versionchanged:: 3.9
15871587
Now supports creating empty sets with ``'set()'``.
15881588

1589+
.. versionchanged:: 3.10
1590+
For string inputs, leading spaces and tabs are now stripped.
1591+
15891592

15901593
.. function:: get_docstring(node, clean=True)
15911594

@@ -1820,4 +1823,4 @@ to stdout. Otherwise, the content is read from stdin.
18201823
`Parso <https://parso.readthedocs.io>`_ is a Python parser that supports
18211824
error recovery and round-trip parsing for different Python versions (in
18221825
multiple Python versions). Parso is also able to list multiple syntax errors
1823-
in your python file.
1826+
in your python file.

Doc/library/codecs.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,14 @@ function:
163163
:class:`CodecInfo` object. In case a search function cannot find
164164
a given encoding, it should return ``None``.
165165

166-
.. note::
167166

168-
Search function registration is not currently reversible,
169-
which may cause problems in some cases, such as unit testing or
170-
module reloading.
167+
.. function:: unregister(search_function)
168+
169+
Unregister a codec search function and clear the registry's cache.
170+
If the search function is not registered, do nothing.
171+
172+
.. versionadded:: 3.10
173+
171174

172175
While the builtin :func:`open` and the associated :mod:`io` module are the
173176
recommended approach for working with encoded text files, this module

Doc/library/configparser.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,30 @@ involves the ``DEFAULT`` section which provides default values for all other
135135
sections [1]_. Note also that keys in sections are
136136
case-insensitive and stored in lowercase [1]_.
137137

138+
It is possible to read several configurations into a single
139+
:class:`ConfigParser`, where the most recently added configuration has the
140+
highest priority. Any conflicting keys are taken from the more recent
141+
configuration while the previously existing keys are retained.
142+
143+
.. doctest::
144+
145+
>>> another_config = configparser.ConfigParser()
146+
>>> another_config.read('example.ini')
147+
['example.ini']
148+
>>> another_config['topsecret.server.com']['Port']
149+
'50022'
150+
>>> another_config.read_string("[topsecret.server.com]\nPort=48484")
151+
>>> another_config['topsecret.server.com']['Port']
152+
'48484'
153+
>>> another_config.read_dict({"topsecret.server.com": {"Port": 21212}})
154+
>>> another_config['topsecret.server.com']['Port']
155+
'21212'
156+
>>> another_config['topsecret.server.com']['ForwardX11']
157+
'no'
158+
159+
This behaviour is equivalent to a :meth:`ConfigParser.read` call with several
160+
files passed to the *filenames* parameter.
161+
138162

139163
Supported Datatypes
140164
-------------------

Doc/library/constants.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ A small number of constants live in the built-in namespace. They are:
1919

2020
.. data:: None
2121

22-
The sole value of the type ``NoneType``. ``None`` is frequently used to
23-
represent the absence of a value, as when default arguments are not passed to a
24-
function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`.
22+
An object frequently used to represent the absence of a value, as when
23+
default arguments are not passed to a function. Assignments to ``None``
24+
are illegal and raise a :exc:`SyntaxError`.
25+
``None`` is the sole instance of the :data:`NoneType` type.
2526

2627

2728
.. data:: NotImplemented
2829

29-
Special value which should be returned by the binary special methods
30+
A special value which should be returned by the binary special methods
3031
(e.g. :meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, :meth:`__rsub__`,
3132
etc.) to indicate that the operation is not implemented with respect to
3233
the other type; may be returned by the in-place binary special methods
3334
(e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose.
3435
It should not be evaluated in a boolean context.
36+
``NotImplemented`` is the sole instance of the :data:`types.NotImplementedType` type.
3537

3638
.. note::
3739

@@ -59,8 +61,9 @@ A small number of constants live in the built-in namespace. They are:
5961
.. index:: single: ...; ellipsis literal
6062
.. data:: Ellipsis
6163

62-
The same as the ellipsis literal "``...``". Special value used mostly in conjunction
64+
The same as the ellipsis literal "``...``". Special value used mostly in conjunction
6365
with extended slicing syntax for user-defined container data types.
66+
``Ellipsis`` is the sole instance of the :data:`types.EllipsisType` type.
6467

6568

6669
.. data:: __debug__

Doc/library/dataclasses.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Module-level decorators, classes, and functions
188188

189189
@dataclass
190190
class C:
191-
mylist: List[int] = field(default_factory=list)
191+
mylist: list[int] = field(default_factory=list)
192192

193193
c = C()
194194
c.mylist += [1, 2, 3]
@@ -301,7 +301,7 @@ Module-level decorators, classes, and functions
301301

302302
@dataclass
303303
class C:
304-
mylist: List[Point]
304+
mylist: list[Point]
305305

306306
p = Point(10, 20)
307307
assert asdict(p) == {'x': 10, 'y': 20}

Doc/library/difflib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
--------------
1919

2020
This module provides classes and functions for comparing sequences. It
21-
can be used for example, for comparing files, and can produce difference
22-
information in various formats, including HTML and context and unified
21+
can be used for example, for comparing files, and can produce information
22+
about file differences in various formats, including HTML and context and unified
2323
diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
2424

2525

0 commit comments

Comments
 (0)