Skip to content

Commit

Permalink
Merge branch 'main' into pythongh-90208-pathlib-glob-oserror-ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed May 10, 2023
2 parents 1b7cbb7 + a33ce66 commit a59709c
Show file tree
Hide file tree
Showing 140 changed files with 3,876 additions and 1,634 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# GitHub
.github/** @ezio-melotti @hugovk

# pre-commit
.pre-commit-config.yaml @hugovk @AlexWaygood

# Build system
configure* @erlend-aasland @corona10

Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint

on: [push, pull_request, workflow_dispatch]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.x"
- uses: pre-commit/action@v3.0.0
4 changes: 4 additions & 0 deletions .github/workflows/require-pr-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
types: [opened, reopened, labeled, unlabeled, synchronize]

permissions:
issues: read
pull-requests: read

jobs:
label:
name: DO-NOT-MERGE / unresolved review
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: trailing-whitespace
types_or: [c, python, rst]
1 change: 1 addition & 0 deletions Doc/howto/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ The flow of log event information in loggers and handlers is illustrated in the
following diagram.

.. image:: logging_flow.png
:class: invert-in-dark-mode

Loggers
^^^^^^^
Expand Down
30 changes: 29 additions & 1 deletion Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ Running Tasks Concurrently
and there is no running event loop.


.. _eager-task-factory:

Eager Task Factory
==================

Expand Down Expand Up @@ -560,6 +562,13 @@ Eager Task Factory
using the provided *custom_task_constructor* when creating a new task instead
of the default :class:`Task`.

*custom_task_constructor* must be a *callable* with the signature matching
the signature of :class:`Task.__init__ <Task>`.
The callable must return a :class:`asyncio.Task`-compatible object.

This function returns a *callable* intended to be used as a task factory of an
event loop via :meth:`loop.set_task_factory(factory) <loop.set_task_factory>`).

.. versionadded:: 3.12


Expand Down Expand Up @@ -1014,7 +1023,7 @@ Introspection
Task Object
===========

.. class:: Task(coro, *, loop=None, name=None, context=None)
.. class:: Task(coro, *, loop=None, name=None, context=None, eager_start=False)

A :class:`Future-like <Future>` object that runs a Python
:ref:`coroutine <coroutine>`. Not thread-safe.
Expand Down Expand Up @@ -1054,6 +1063,13 @@ Task Object
If no *context* is provided, the Task copies the current context
and later runs its coroutine in the copied context.

An optional keyword-only *eager_start* argument allows eagerly starting
the execution of the :class:`asyncio.Task` at task creation time.
If set to ``True`` and the event loop is running, the task will start
executing the coroutine immediately, until the first time the coroutine
blocks. If the coroutine returns or raises without blocking, the task
will be finished eagerly and will skip scheduling to the event loop.

.. versionchanged:: 3.7
Added support for the :mod:`contextvars` module.

Expand All @@ -1067,6 +1083,9 @@ Task Object
.. versionchanged:: 3.11
Added the *context* parameter.

.. versionchanged:: 3.12
Added the *eager_start* parameter.

.. method:: done()

Return ``True`` if the Task is *done*.
Expand Down Expand Up @@ -1157,8 +1176,17 @@ Task Object

Return the coroutine object wrapped by the :class:`Task`.

.. note::

This will return ``None`` for Tasks which have already
completed eagerly. See the :ref:`Eager Task Factory <eager-task-factory>`.

.. versionadded:: 3.8

.. versionchanged:: 3.12

Newly added eager task execution means result may be ``None``.

.. method:: get_context()

Return the :class:`contextvars.Context` object
Expand Down
22 changes: 12 additions & 10 deletions Doc/library/bisect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ method to determine whether a value has been found. Instead, the
functions only call the :meth:`__lt__` method and will return an insertion
point between values in an array.

.. _bisect functions:

The following functions are provided:


Expand Down Expand Up @@ -55,7 +57,7 @@ The following functions are provided:
.. function:: bisect_right(a, x, lo=0, hi=len(a), *, key=None)
bisect(a, x, lo=0, hi=len(a), *, key=None)
Similar to :func:`bisect_left`, but returns an insertion point which comes
Similar to :py:func:`~bisect.bisect_left`, but returns an insertion point which comes
after (to the right of) any existing entries of *x* in *a*.

The returned insertion point *ip* partitions the array *a* into two slices
Expand All @@ -70,7 +72,7 @@ The following functions are provided:

Insert *x* in *a* in sorted order.

This function first runs :func:`bisect_left` to locate an insertion point.
This function first runs :py:func:`~bisect.bisect_left` to locate an insertion point.
Next, it runs the :meth:`insert` method on *a* to insert *x* at the
appropriate position to maintain sort order.

Expand All @@ -87,10 +89,10 @@ The following functions are provided:
.. function:: insort_right(a, x, lo=0, hi=len(a), *, key=None)
insort(a, x, lo=0, hi=len(a), *, key=None)
Similar to :func:`insort_left`, but inserting *x* in *a* after any existing
Similar to :py:func:`~bisect.insort_left`, but inserting *x* in *a* after any existing
entries of *x*.

This function first runs :func:`bisect_right` to locate an insertion point.
This function first runs :py:func:`~bisect.bisect_right` to locate an insertion point.
Next, it runs the :meth:`insert` method on *a* to insert *x* at the
appropriate position to maintain sort order.

Expand Down Expand Up @@ -120,7 +122,7 @@ thoughts in mind:
they are used. Consequently, if the search functions are used in a loop,
the key function may be called again and again on the same array elements.
If the key function isn't fast, consider wrapping it with
:func:`functools.cache` to avoid duplicate computations. Alternatively,
:py:func:`functools.cache` to avoid duplicate computations. Alternatively,
consider searching an array of precomputed keys to locate the insertion
point (as shown in the examples section below).

Expand All @@ -140,7 +142,7 @@ thoughts in mind:
Searching Sorted Lists
----------------------

The above :func:`bisect` functions are useful for finding insertion points but
The above `bisect functions`_ are useful for finding insertion points but
can be tricky or awkward to use for common searching tasks. The following five
functions show how to transform them into the standard lookups for sorted
lists::
Expand Down Expand Up @@ -186,8 +188,8 @@ Examples

.. _bisect-example:

The :func:`bisect` function can be useful for numeric table lookups. This
example uses :func:`bisect` to look up a letter grade for an exam score (say)
The :py:func:`~bisect.bisect` function can be useful for numeric table lookups. This
example uses :py:func:`~bisect.bisect` to look up a letter grade for an exam score (say)
based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is
a 'B', and so on::

Expand All @@ -198,8 +200,8 @@ a 'B', and so on::
>>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
['F', 'A', 'C', 'C', 'B', 'A', 'A']

The :func:`bisect` and :func:`insort` functions also work with lists of
tuples. The *key* argument can serve to extract the field used for ordering
The :py:func:`~bisect.bisect` and :py:func:`~bisect.insort` functions also work with
lists of tuples. The *key* argument can serve to extract the field used for ordering
records in a table::

>>> from collections import namedtuple
Expand Down
8 changes: 8 additions & 0 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,14 @@ iterations of the loop.

.. versionadded:: 3.12

.. opcode:: LOAD_FAST_AND_CLEAR (var_num)

Pushes a reference to the local ``co_varnames[var_num]`` onto the stack (or
pushes ``NULL`` onto the stack if the local variable has not been
initialized) and sets ``co_varnames[var_num]`` to ``NULL``.

.. versionadded:: 3.12

.. opcode:: STORE_FAST (var_num)

Stores ``STACK.pop()`` into the local ``co_varnames[var_num]``.
Expand Down
1 change: 1 addition & 0 deletions Doc/library/hashlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ Constructor functions also accept the following tree hashing parameters:

.. figure:: hashlib-blake2-tree.png
:alt: Explanation of tree mode parameters.
:class: invert-in-dark-mode

See section 2.10 in `BLAKE2 specification
<https://www.blake2.net/blake2_20130129.pdf>`_ for comprehensive review of tree
Expand Down
20 changes: 18 additions & 2 deletions Doc/library/http.client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ HTTPConnection Objects
encode_chunked=False)

This will send a request to the server using the HTTP request
method *method* and the selector *url*.
method *method* and the request URI *url*. The provided *url* must be
an absolute path to conform with :rfc:`RFC 2616 §5.1.2 <2616#section-5.1.2>`
(unless connecting to an HTTP proxy server or using the ``OPTIONS`` or
``CONNECT`` methods).

If *body* is specified, the specified data is sent after the headers are
finished. It may be a :class:`str`, a :term:`bytes-like object`, an
Expand All @@ -279,7 +282,10 @@ HTTPConnection Objects
iterable are sent as is until the iterable is exhausted.

The *headers* argument should be a mapping of extra HTTP headers to send
with the request.
with the request. A :rfc:`Host header <2616#section-14.23>`
must be provided to conform with :rfc:`RFC 2616 §5.1.2 <2616#section-5.1.2>`
(unless connecting to an HTTP proxy server or using the ``OPTIONS`` or
``CONNECT`` methods).

If *headers* contains neither Content-Length nor Transfer-Encoding,
but there is a request body, one of those
Expand All @@ -298,6 +304,16 @@ HTTPConnection Objects
HTTPConnection object assumes that all encoding is handled by the
calling code. If it is ``True``, the body will be chunk-encoded.

For example, to perform a ``GET`` request to ``https://docs.python.org/3/``::

>>> import http.client
>>> host = "docs.python.org"
>>> conn = http.client.HTTPSConnection(host)
>>> conn.request("GET", "/3/", headers={"Host": host})
>>> response = conn.getresponse()
>>> print(response.status, response.reason)
200 OK

.. note::
Chunked transfer encoding has been added to the HTTP protocol
version 1.1. Unless the HTTP server is known to handle HTTP 1.1,
Expand Down
1 change: 1 addition & 0 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ inherit from pure paths but also provide I/O operations.

.. image:: pathlib-inheritance.png
:align: center
:class: invert-in-dark-mode

If you've never used this module before or just aren't sure which class is
right for your task, :class:`Path` is most likely what you need. It instantiates
Expand Down
40 changes: 25 additions & 15 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2130,15 +2130,10 @@ Corresponding to collections in :mod:`collections.abc`

.. class:: ByteString(Sequence[int])

A generic version of :class:`collections.abc.ByteString`.

This type represents the types :class:`bytes`, :class:`bytearray`,
and :class:`memoryview` of byte sequences.

As a shorthand for this type, :class:`bytes` can be used to
annotate arguments of any of the types mentioned above.

.. deprecated:: 3.9
.. deprecated-removed:: 3.9 3.14
Prefer :class:`collections.abc.Buffer`, or a union like ``bytes | bytearray | memoryview``.

.. class:: Collection(Sized, Iterable[T_co], Container[T_co])
Expand Down Expand Up @@ -2881,24 +2876,37 @@ Introspection helpers
if a default value equal to ``None`` was set.
Now the annotation is returned unchanged.

.. function:: get_args(tp)
.. function:: get_origin(tp)

Provide basic introspection for generic types and special typing forms.

For a typing object of the form ``X[Y, Z, ...]`` these functions return
``X`` and ``(Y, Z, ...)``. If ``X`` is a generic alias for a builtin or
Get the unsubscripted version of a type: for a typing object of the form
``X[Y, Z, ...]`` return ``X``. If ``X`` is a generic alias for a builtin or
:mod:`collections` class, it gets normalized to the original class.
If ``X`` is an instance of :class:`ParamSpecArgs` or :class:`ParamSpecKwargs`,
return the underlying :class:`ParamSpec`.
Return ``None`` for unsupported objects.
Examples::

assert get_origin(str) is None
assert get_origin(Dict[str, int]) is dict
assert get_origin(Union[int, str]) is Union
P = ParamSpec('P')
assert get_origin(P.args) is P
assert get_origin(P.kwargs) is P

.. versionadded:: 3.8

.. function:: get_args(tp)

Get type arguments with all substitutions performed: for a typing object
of the form ``X[Y, Z, ...]`` return ``(Y, Z, ...)``.
If ``X`` is a union or :class:`Literal` contained in another
generic type, the order of ``(Y, Z, ...)`` may be different from the order
of the original arguments ``[Y, Z, ...]`` due to type caching.
For unsupported objects return ``None`` and ``()`` correspondingly.
Return ``()`` for unsupported objects.
Examples::

assert get_origin(Dict[str, int]) is dict
assert get_args(int) == ()
assert get_args(Dict[int, str]) == (int, str)

assert get_origin(Union[int, str]) is Union
assert get_args(Union[int, str]) == (int, str)

.. versionadded:: 3.8
Expand Down Expand Up @@ -2977,6 +2985,8 @@ convenience. This is subject to change, and not all deprecations are listed.
| ``typing`` versions of standard | 3.9 | Undecided | :pep:`585` |
| collections | | | |
+----------------------------------+---------------+-------------------+----------------+
| ``typing.ByteString`` | 3.9 | 3.14 | :gh:`91896` |
+----------------------------------+---------------+-------------------+----------------+
| ``typing.Text`` | 3.11 | Undecided | :gh:`92332` |
+----------------------------------+---------------+-------------------+----------------+
| ``typing.Hashable`` and | 3.12 | Undecided | :gh:`94309` |
Expand Down
20 changes: 10 additions & 10 deletions Doc/tools/extensions/pyspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,14 @@ def process_audit_events(app, doctree, fromdocname):
node.replace_self(table)


def patch_pairindextypes(app) -> None:
def patch_pairindextypes(app, _env) -> None:
"""Remove all entries from ``pairindextypes`` before writing POT files.
We want to run this just before writing output files, as the check to
circumvent is in ``I18nBuilder.write_doc()``.
As such, we link this to ``env-check-consistency``, even though it has
nothing to do with the environment consistency check.
"""
if app.builder.name != 'gettext':
return

Expand All @@ -688,14 +695,7 @@ def patch_pairindextypes(app) -> None:
# the Sphinx-translated pairindextypes values. As we intend to move
# away from this, we need Sphinx to believe that these values don't
# exist, by deleting them when using the gettext builder.

pairindextypes.pop('module', None)
pairindextypes.pop('keyword', None)
pairindextypes.pop('operator', None)
pairindextypes.pop('object', None)
pairindextypes.pop('exception', None)
pairindextypes.pop('statement', None)
pairindextypes.pop('builtin', None)
pairindextypes.clear()


def setup(app):
Expand All @@ -719,7 +719,7 @@ def setup(app):
app.add_directive_to_domain('py', 'awaitablemethod', PyAwaitableMethod)
app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
app.add_directive('miscnews', MiscNews)
app.connect('builder-inited', patch_pairindextypes)
app.connect('env-check-consistency', patch_pairindextypes)
app.connect('doctree-resolved', process_audit_events)
app.connect('env-merge-info', audit_events_merge)
app.connect('env-purge-doc', audit_events_purge)
Expand Down
Loading

0 comments on commit a59709c

Please sign in to comment.