Skip to content

Commit

Permalink
Merge branch 'main' into argparse-positional-dest
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored Oct 11, 2024
2 parents 36c5c20 + b3aa1b5 commit a9295f0
Show file tree
Hide file tree
Showing 81 changed files with 1,220 additions and 943 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/reusable-change-detection.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---

name: Change detection
name: Reusable change detection

on: # yamllint disable-line rule:truthy
workflow_call:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable-docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docs
name: Reusable Docs

on:
workflow_call:
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
doctest:
name: 'Doctest'
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-macos.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Reusable macOS

on:
workflow_call:
inputs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-tsan.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Reusable Thread Sanitizer

on:
workflow_call:
inputs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Reusable Ubuntu

on:
workflow_call:
inputs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-wasi.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Reusable WASI

on:
workflow_call:
inputs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-windows-msi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: TestsMSI
name: Reusable Windows MSI

on:
workflow_call:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-windows.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Reusable Windows

on:
workflow_call:
inputs:
Expand Down
20 changes: 13 additions & 7 deletions Doc/c-api/contextvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,24 @@ Context object management functions:
.. c:type:: PyContextEvent
Enumeration of possible context object watcher events:
- ``Py_CONTEXT_EVENT_ENTER``
- ``Py_CONTEXT_EVENT_EXIT``
- ``Py_CONTEXT_EVENT_ENTER``: A context has been entered, causing the
:term:`current context` to switch to it. The object passed to the watch
callback is the now-current :class:`contextvars.Context` object. Each
enter event will eventually have a corresponding exit event for the same
context object after any subsequently entered contexts have themselves been
exited.
- ``Py_CONTEXT_EVENT_EXIT``: A context is about to be exited, which will
cause the :term:`current context` to switch back to what it was before the
context was entered. The object passed to the watch callback is the
still-current :class:`contextvars.Context` object.
.. versionadded:: 3.14
.. c:type:: int (*PyContext_WatchCallback)(PyContextEvent event, PyContext* ctx)
Type of a context object watcher callback function.
If *event* is ``Py_CONTEXT_EVENT_ENTER``, then the callback is invoked
after *ctx* has been set as the current context for the current thread.
Otherwise, the callback is invoked before the deactivation of *ctx* as the current context
and the restoration of the previous contex object for the current thread.
Context object watcher callback function. The object passed to the callback
is event-specific; see :c:type:`PyContextEvent` for details.
If the callback returns with an exception set, it must return ``-1``; this
exception will be printed as an unraisable exception using
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,8 @@ object.
Discard the internal Unicode buffer and destroy the writer instance.
If *writer* is ``NULL``, no operation is performed.
.. c:function:: int PyUnicodeWriter_WriteChar(PyUnicodeWriter *writer, Py_UCS4 ch)
Write the single Unicode character *ch* into *writer*.
Expand Down
32 changes: 25 additions & 7 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import sys
import time

import sphinx

sys.path.append(os.path.abspath('tools/extensions'))
sys.path.append(os.path.abspath('includes'))

Expand All @@ -21,6 +23,7 @@

extensions = [
'audit_events',
'availability',
'c_annotations',
'glossary_search',
'lexers',
Expand Down Expand Up @@ -61,7 +64,10 @@

# General substitutions.
project = 'Python'
copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation"
if sphinx.version_info[:2] >= (8, 1):
copyright = "2001-%Y, Python Software Foundation"
else:
copyright = f"2001-{time.strftime('%Y')}, Python Software Foundation"

# We look for the Include/patchlevel.h file in the current Python source tree
# and replace the values accordingly.
Expand Down Expand Up @@ -360,10 +366,14 @@
}

# This 'Last updated on:' timestamp is inserted at the bottom of every page.
html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
html_last_updated_fmt = time.strftime(
'%b %d, %Y (%H:%M UTC)', time.gmtime(html_time)
)
html_last_updated_fmt = '%b %d, %Y (%H:%M UTC)'
if sphinx.version_info[:2] >= (8, 1):
html_last_updated_use_utc = True
else:
html_time = int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
html_last_updated_fmt = time.strftime(
html_last_updated_fmt, time.gmtime(html_time)
)

# Path to find HTML templates.
templates_path = ['tools/templates']
Expand Down Expand Up @@ -595,13 +605,21 @@
# mapping unique short aliases to a base URL and a prefix.
# https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
extlinks = {
"cve": ("https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s", "CVE-%s"),
"cwe": ("https://cwe.mitre.org/data/definitions/%s.html", "CWE-%s"),
"pypi": ("https://pypi.org/project/%s/", "%s"),
"source": (SOURCE_URI, "%s"),
}
extlinks_detect_hardcoded_links = True

if sphinx.version_info[:2] < (8, 1):
# Sphinx 8.1 has in-built CVE and CWE roles.
extlinks |= {
"cve": (
"https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s",
"CVE-%s",
),
"cwe": ("https://cwe.mitre.org/data/definitions/%s.html", "CWE-%s"),
}

# Options for c_annotations
# -------------------------

Expand Down
40 changes: 31 additions & 9 deletions Doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,33 @@ Glossary
advanced mathematical feature. If you're not aware of a need for them,
it's almost certain you can safely ignore them.

context
This term has different meanings depending on where and how it is used.
Some common meanings:

* The temporary state or environment established by a :term:`context
manager` via a :keyword:`with` statement.
* The collection of key­value bindings associated with a particular
:class:`contextvars.Context` object and accessed via
:class:`~contextvars.ContextVar` objects. Also see :term:`context
variable`.
* A :class:`contextvars.Context` object. Also see :term:`current
context`.

context management protocol
The :meth:`~object.__enter__` and :meth:`~object.__exit__` methods called
by the :keyword:`with` statement. See :pep:`343`.

context manager
An object which controls the environment seen in a :keyword:`with`
statement by defining :meth:`~object.__enter__` and :meth:`~object.__exit__` methods.
See :pep:`343`.
An object which implements the :term:`context management protocol` and
controls the environment seen in a :keyword:`with` statement. See
:pep:`343`.

context variable
A variable which can have different values depending on its context.
This is similar to Thread-Local Storage in which each execution
thread may have a different value for a variable. However, with context
variables, there may be several contexts in one execution thread and the
main usage for context variables is to keep track of variables in
A variable whose value depends on which context is the :term:`current
context`. Values are accessed via :class:`contextvars.ContextVar`
objects. Context variables are primarily used to isolate state between
concurrent asynchronous tasks.
See :mod:`contextvars`.

contiguous
.. index:: C-contiguous, Fortran contiguous
Expand Down Expand Up @@ -311,6 +325,14 @@ Glossary
is used when necessary to distinguish this implementation from others
such as Jython or IronPython.

current context
The :term:`context` (:class:`contextvars.Context` object) that is
currently used by :class:`~contextvars.ContextVar` objects to access (get
or set) the values of :term:`context variables <context variable>`. Each
thread has its own current context. Frameworks for executing asynchronous
tasks (see :mod:`asyncio`) associate each task with a context which
becomes the current context whenever the task starts or resumes execution.

decorator
A function returning another function, usually applied as a function
transformation using the ``@wrapper`` syntax. Common examples for
Expand Down
8 changes: 5 additions & 3 deletions Doc/library/_thread.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ In addition to these methods, lock objects can also be used via the
* Calling :func:`sys.exit` or raising the :exc:`SystemExit` exception is
equivalent to calling :func:`_thread.exit`.

* It is not possible to interrupt the :meth:`~threading.Lock.acquire` method on
a lock --- the :exc:`KeyboardInterrupt` exception will happen after the lock
has been acquired.
* It is platform-dependent whether the :meth:`~threading.Lock.acquire` method
on a lock can be interrupted (so that the :exc:`KeyboardInterrupt` exception
will happen immediately, rather than only after the lock has been acquired or
the operation has timed out). It can be interrupted on POSIX, but not on
Windows.

* When the main thread exits, it is system defined whether the other threads
survive. On most systems, they are killed without executing
Expand Down
5 changes: 3 additions & 2 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ exit_on_error
^^^^^^^^^^^^^

Normally, when you pass an invalid argument list to the :meth:`~ArgumentParser.parse_args`
method of an :class:`ArgumentParser`, it will exit with error info.
method of an :class:`ArgumentParser`, it will print a *message* to :data:`sys.stderr` and exit with a status
code of 2.

If the user would like to catch errors manually, the feature can be enabled by setting
``exit_on_error`` to ``False``::
Expand Down Expand Up @@ -601,7 +602,7 @@ The add_argument() method
The following sections describe how each of these are used.


.. _name_or_flags:
.. _`name or flags`:

name or flags
^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions Doc/library/configparser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ can be customized by end users easily.

import os
os.remove("example.ini")
os.remove("override.ini")


Quick Start
Expand Down
98 changes: 68 additions & 30 deletions Doc/library/contextvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,51 +144,89 @@ Manual Context Management
To get a copy of the current context use the
:func:`~contextvars.copy_context` function.

Every thread will have a different top-level :class:`~contextvars.Context`
object. This means that a :class:`ContextVar` object behaves in a similar
fashion to :func:`threading.local` when values are assigned in different
threads.
Each thread has its own effective stack of :class:`!Context` objects. The
:term:`current context` is the :class:`!Context` object at the top of the
current thread's stack. All :class:`!Context` objects in the stacks are
considered to be *entered*.

*Entering* a context, which can be done by calling its :meth:`~Context.run`
method, makes the context the current context by pushing it onto the top of
the current thread's context stack.

*Exiting* from the current context, which can be done by returning from the
callback passed to the :meth:`~Context.run` method, restores the current
context to what it was before the context was entered by popping the context
off the top of the context stack.

Since each thread has its own context stack, :class:`ContextVar` objects
behave in a similar fashion to :func:`threading.local` when values are
assigned in different threads.

Attempting to enter an already entered context, including contexts entered in
other threads, raises a :exc:`RuntimeError`.

After exiting a context, it can later be re-entered (from any thread).

Any changes to :class:`ContextVar` values via the :meth:`ContextVar.set`
method are recorded in the current context. The :meth:`ContextVar.get`
method returns the value associated with the current context. Exiting a
context effectively reverts any changes made to context variables while the
context was entered (if needed, the values can be restored by re-entering the
context).

Context implements the :class:`collections.abc.Mapping` interface.

.. method:: run(callable, *args, **kwargs)

Execute ``callable(*args, **kwargs)`` code in the context object
the *run* method is called on. Return the result of the execution
or propagate an exception if one occurred.
Enters the Context, executes ``callable(*args, **kwargs)``, then exits the
Context. Returns *callable*'s return value, or propagates an exception if
one occurred.

Example:

.. testcode::

import contextvars

Any changes to any context variables that *callable* makes will
be contained in the context object::
var = contextvars.ContextVar('var')
var.set('spam')
print(var.get()) # 'spam'

var = ContextVar('var')
var.set('spam')
ctx = contextvars.copy_context()

def main():
# 'var' was set to 'spam' before
# calling 'copy_context()' and 'ctx.run(main)', so:
# var.get() == ctx[var] == 'spam'
def main():
# 'var' was set to 'spam' before
# calling 'copy_context()' and 'ctx.run(main)', so:
print(var.get()) # 'spam'
print(ctx[var]) # 'spam'

var.set('ham')
var.set('ham')

# Now, after setting 'var' to 'ham':
# var.get() == ctx[var] == 'ham'
# Now, after setting 'var' to 'ham':
print(var.get()) # 'ham'
print(ctx[var]) # 'ham'

ctx = copy_context()
# Any changes that the 'main' function makes to 'var'
# will be contained in 'ctx'.
ctx.run(main)

# Any changes that the 'main' function makes to 'var'
# will be contained in 'ctx'.
ctx.run(main)
# The 'main()' function was run in the 'ctx' context,
# so changes to 'var' are contained in it:
print(ctx[var]) # 'ham'

# The 'main()' function was run in the 'ctx' context,
# so changes to 'var' are contained in it:
# ctx[var] == 'ham'
# However, outside of 'ctx', 'var' is still set to 'spam':
print(var.get()) # 'spam'

# However, outside of 'ctx', 'var' is still set to 'spam':
# var.get() == 'spam'
.. testoutput::
:hide:

The method raises a :exc:`RuntimeError` when called on the same
context object from more than one OS thread, or when called
recursively.
spam
spam
spam
ham
ham
ham
spam

.. method:: copy()

Expand Down
Loading

0 comments on commit a9295f0

Please sign in to comment.