Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into bpo_1635741_1
Browse files Browse the repository at this point in the history
* origin/master: (113 commits)
  bpo-41773: Raise exception for non-finite weights in random.choices().  (pythonGH-22441)
  bpo-41873: Add vectorcall for float() (pythonGH-22432)
  bpo-41861: Convert _sqlite3 PrepareProtocolType to heap type (pythonGH-22428)
  bpo-41842: Add codecs.unregister() function (pythonGH-22360)
  bpo-41875: Use __builtin_unreachable when possible (pythonGH-22433)
  bpo-40105: ZipFile truncate in append mode with shorter comment (pythonGH-19337)
  bpo-41870: Use PEP 590 vectorcall to speed up bool()  (pythonGH-22427)
  [doc] Leverage the fact that the actual types can now be indexed for typing (pythonGH-22340)
  bpo-41861: Convert _sqlite3 cache and node static types to heap types (pythonGH-22417)
  bpo-41858: Clarify line in optparse doc (pythonGH-22407)
  Revert "Fix all Python Cookbook links (python#22205)" (pythonGH-22424)
  bpo-1635741: Port _bisect module to multi-phase init (pythonGH-22415)
  bpo-41428: Fix compiler warning in unionobject.c (pythonGH-22416)
  Fix logging error message (pythonGH-22410)
  bpo-39934: Account for control blocks in 'except' in compiler. (pythonGH-22395)
  bpo-41775: Make 'IDLE Shell' the shell title  (python#22399)
  bpo-41428: Fix compiler warnings in unionobject.c (pythonGH-22388)
  bpo-41654: Fix compiler warning in MemoryError_dealloc() (pythonGH-22387)
  bpo-41833: threading.Thread now uses the target name (pythonGH-22357)
  bpo-30155: Add macros to get tzinfo from datetime instances (pythonGH-21633)
  ...
  • Loading branch information
shihai1991 committed Sep 29, 2020
2 parents 3795420 + b0dfc75 commit e3b9365
Show file tree
Hide file tree
Showing 224 changed files with 4,452 additions and 2,314 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ matrix:
env: TESTING=docs
before_script:
- cd Doc
# Sphinx is pinned so that new versions that introduce new warnings won't suddenly cause build failures.
# (Updating the version is fine as long as no warnings are raised by doing so.)
# The theme used by the docs is stored separately, so we need to install that as well.
- python -m pip install sphinx==2.2.0 blurb python-docs-theme
- make venv PYTHON=python
script:
- make check suspicious html SPHINXOPTS="-q -W -j4"
- name: "Documentation tests"
Expand Down
2 changes: 1 addition & 1 deletion Doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ clean:
venv:
$(PYTHON) -m venv $(VENVDIR)
$(VENVDIR)/bin/python3 -m pip install -U pip setuptools
$(VENVDIR)/bin/python3 -m pip install -U Sphinx==3.2.1 blurb python-docs-theme
$(VENVDIR)/bin/python3 -m pip install -r requirements.txt
@echo "The venv has been created in the $(VENVDIR) directory"

dist:
Expand Down
8 changes: 8 additions & 0 deletions Doc/c-api/codec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ Codec registry and support functions
As side effect, this tries to load the :mod:`encodings` package, if not yet
done, to make sure that it is always first in the list of search functions.
.. c:function:: int PyCodec_Unregister(PyObject *search_function)
Unregister a codec search function and clear the registry's cache.
If the search function is not registered, do nothing.
Return 0 on success. Raise an exception and return -1 on error.
.. versionadded:: 3.10
.. c:function:: int PyCodec_KnownEncoding(const char *encoding)
Return ``1`` or ``0`` depending on whether there is a registered codec for
Expand Down
11 changes: 11 additions & 0 deletions Doc/c-api/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ must not be ``NULL``, and the type is not checked:
Return the microsecond, as an int from 0 through 999999.
.. c:function:: PyObject* PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)
Return the tzinfo (which may be ``None``).
.. versionadded:: 3.10
Macros to extract fields from time objects. The argument must be an instance of
:c:data:`PyDateTime_Time`, including subclasses. The argument must not be ``NULL``,
Expand All @@ -209,6 +214,12 @@ and the type is not checked:
Return the microsecond, as an int from 0 through 999999.
.. c:function:: PyObject* PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)
Return the tzinfo (which may be ``None``).
.. versionadded:: 3.10
Macros to extract fields from time delta objects. The argument must be an
instance of :c:data:`PyDateTime_Delta`, including subclasses. The argument must
Expand Down
15 changes: 15 additions & 0 deletions Doc/c-api/gen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
The C structure used for generator objects.


.. c:type:: PySendResult
The enum value used to represent different results of :c:func:`PyGen_Send`.


.. c:var:: PyTypeObject PyGen_Type
The type object corresponding to generator objects.
Expand Down Expand Up @@ -42,3 +47,13 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
A reference to *frame* is stolen by this function. The *frame* argument
must not be ``NULL``.
.. c:function:: PySendResult PyGen_Send(PyGenObject *gen, PyObject *arg, PyObject **presult)
Sends the *arg* value into the generator *gen*. Coroutine objects
are also allowed to be as the *gen* argument but they need to be
explicitly casted to PyGenObject*. Returns:
- ``PYGEN_RETURN`` if generator returns. Return value is returned via *presult*.
- ``PYGEN_NEXT`` if generator yields. Yielded value is returned via *presult*.
- ``PYGEN_ERROR`` if generator has raised and exception. *presult* is set to ``NULL``.
10 changes: 10 additions & 0 deletions Doc/data/refcounts.dat
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,11 @@ PyGen_NewWithQualName:PyFrameObject*:frame:0:
PyGen_NewWithQualName:PyObject*:name:0:
PyGen_NewWithQualName:PyObject*:qualname:0:

PyGen_Send:int:::
PyGen_Send:PyGenObject*:gen:0:
PyGen_Send:PyObject*:arg:0:
PyGen_Send:PyObject**:presult:+1:

PyCoro_CheckExact:int:::
PyCoro_CheckExact:PyObject*:ob:0:

Expand Down Expand Up @@ -2283,6 +2288,11 @@ PyType_CheckExact:PyObject*:o:0:
PyType_FromSpec:PyObject*::+1:
PyType_FromSpec:PyType_Spec*:spec::

PyType_FromModuleAndSpec:PyObject*::+1:
PyType_FromModuleAndSpec:PyObject*:module:+1:
PyType_FromModuleAndSpec:PyType_Spec*:spec::
PyType_FromModuleAndSpec:PyObject*:bases:0:

PyType_FromSpecWithBases:PyObject*::+1:
PyType_FromSpecWithBases:PyType_Spec*:spec::
PyType_FromSpecWithBases:PyObject*:bases:0:
Expand Down
15 changes: 7 additions & 8 deletions Doc/faq/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1504,20 +1504,19 @@ Most :meth:`__setattr__` implementations must modify ``self.__dict__`` to store
local state for self without causing an infinite recursion.


How do I call a method defined in a base class from a derived class that overrides it?
--------------------------------------------------------------------------------------
How do I call a method defined in a base class from a derived class that extends it?
------------------------------------------------------------------------------------

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

class Derived(Base):
def meth(self):
super(Derived, self).meth()
super().meth() # calls Base.meth

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


How can I organize my code to make it easier to change the base class?
Expand Down
10 changes: 3 additions & 7 deletions Doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1084,19 +1084,15 @@ Glossary
Type aliases are useful for simplifying :term:`type hints <type hint>`.
For example::

from typing import List, Tuple

def remove_gray_shades(
colors: List[Tuple[int, int, int]]) -> List[Tuple[int, int, int]]:
colors: list[tuple[int, int, int]]) -> list[tuple[int, int, int]]:
pass

could be made more readable like this::

from typing import List, Tuple

Color = Tuple[int, int, int]
Color = tuple[int, int, int]

def remove_gray_shades(colors: List[Color]) -> List[Color]:
def remove_gray_shades(colors: list[Color]) -> list[Color]:
pass

See :mod:`typing` and :pep:`484`, which describe this functionality.
Expand Down
11 changes: 7 additions & 4 deletions Doc/library/codecs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ function:
:class:`CodecInfo` object. In case a search function cannot find
a given encoding, it should return ``None``.

.. note::

Search function registration is not currently reversible,
which may cause problems in some cases, such as unit testing or
module reloading.
.. function:: unregister(search_function)

Unregister a codec search function and clear the registry's cache.
If the search function is not registered, do nothing.

.. versionadded:: 3.10


While the builtin :func:`open` and the associated :mod:`io` module are the
recommended approach for working with encoded text files, this module
Expand Down
24 changes: 24 additions & 0 deletions Doc/library/configparser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ involves the ``DEFAULT`` section which provides default values for all other
sections [1]_. Note also that keys in sections are
case-insensitive and stored in lowercase [1]_.

It is possible to read several configurations into a single
:class:`ConfigParser`, where the most recently added configuration has the
highest priority. Any conflicting keys are taken from the more recent
configuration while the previously existing keys are retained.

.. doctest::

>>> another_config = configparser.ConfigParser()
>>> another_config.read('example.ini')
['example.ini']
>>> another_config['topsecret.server.com']['Port']
'50022'
>>> another_config.read_string("[topsecret.server.com]\nPort=48484")
>>> another_config['topsecret.server.com']['Port']
'48484'
>>> another_config.read_dict({"topsecret.server.com": {"Port": 21212}})
>>> another_config['topsecret.server.com']['Port']
'21212'
>>> another_config['topsecret.server.com']['ForwardX11']
'no'

This behaviour is equivalent to a :meth:`ConfigParser.read` call with several
files passed to the *filenames* parameter.


Supported Datatypes
-------------------
Expand Down
13 changes: 8 additions & 5 deletions Doc/library/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ A small number of constants live in the built-in namespace. They are:

.. data:: None

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


.. data:: NotImplemented

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

.. note::

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

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


.. data:: __debug__
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/difflib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
--------------

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


Expand Down
Loading

0 comments on commit e3b9365

Please sign in to comment.