Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/codecs/ignore-…
Browse files Browse the repository at this point in the history
…handler-129173
  • Loading branch information
picnixz committed Jan 23, 2025
2 parents d2d5ccd + 75f59bb commit c323e3b
Show file tree
Hide file tree
Showing 138 changed files with 5,845 additions and 2,441 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}-reusable
cancel-in-progress: true

env:
FORCE_COLOR: 1

jobs:
check_source:
name: Change detection
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/jit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
FORCE_COLOR: 1

jobs:
interpreter:
name: Interpreter (Debug)
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/reusable-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
required: true
type: string

env:
FORCE_COLOR: 1

jobs:
build_macos:
name: build and test (${{ inputs.os }})
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/reusable-tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ on:
required: true
type: string

env:
FORCE_COLOR: 1

jobs:
build_tsan_reusable:
name: 'Thread sanitizer'
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/reusable-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ on:
required: true
type: string

env:
FORCE_COLOR: 1

jobs:
build_ubuntu_reusable:
name: build and test (${{ inputs.os }})
timeout-minutes: 60
runs-on: ${{ inputs.os }}
env:
FORCE_COLOR: 1
OPENSSL_VER: 3.0.15
PYTHONSTRICTEXTENSIONBUILD: 1
TERM: linux
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/reusable-wasi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
required: true
type: string

env:
FORCE_COLOR: 1

jobs:
build_wasi_reusable:
name: 'build and test'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/reusable-windows-msi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
permissions:
contents: read

env:
FORCE_COLOR: 1

jobs:
build:
name: installer for ${{ inputs.arch }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/reusable-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
default: false

env:
FORCE_COLOR: 1
IncludeUwp: >-
true
Expand Down
18 changes: 18 additions & 0 deletions Doc/deprecations/c-api-pending-removal-in-3.18.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Pending removal in Python 3.18
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* Deprecated private functions (:gh:`128863`):

* :c:func:`!_PyBytes_Join`: use :c:func:`PyBytes_Join`.
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
* :c:func:`!_PyDict_Pop()`: :c:func:`PyDict_Pop`.
* :c:func:`!_PyLong_Sign()`: use :c:func:`PyLong_GetSign`.
* :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.

The `pythoncapi-compat project
<https://github.com/python/pythoncapi-compat/>`__ can be used to get these
new public functions on Python 3.13 and older.
145 changes: 145 additions & 0 deletions Doc/library/asyncio-graph.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
.. currentmodule:: asyncio


.. _asyncio-graph:

========================
Call Graph Introspection
========================

**Source code:** :source:`Lib/asyncio/graph.py`

-------------------------------------

asyncio has powerful runtime call graph introspection utilities
to trace the entire call graph of a running *coroutine* or *task*, or
a suspended *future*. These utilities and the underlying machinery
can be used from within a Python program or by external profilers
and debuggers.

.. versionadded:: next


.. function:: print_call_graph(future=None, /, *, file=None, depth=1, limit=None)

Print the async call graph for the current task or the provided
:class:`Task` or :class:`Future`.

This function prints entries starting from the top frame and going
down towards the invocation point.

The function receives an optional *future* argument.
If not passed, the current running task will be used.

If the function is called on *the current task*, the optional
keyword-only *depth* argument can be used to skip the specified
number of frames from top of the stack.

If the optional keyword-only *limit* argument is provided, each call stack
in the resulting graph is truncated to include at most ``abs(limit)``
entries. If *limit* is positive, the entries left are the closest to
the invocation point. If *limit* is negative, the topmost entries are
left. If *limit* is omitted or ``None``, all entries are present.
If *limit* is ``0``, the call stack is not printed at all, only
"awaited by" information is printed.

If *file* is omitted or ``None``, the function will print
to :data:`sys.stdout`.

**Example:**

The following Python code:

.. code-block:: python
import asyncio
async def test():
asyncio.print_call_graph()
async def main():
async with asyncio.TaskGroup() as g:
g.create_task(test())
asyncio.run(main())
will print::

* Task(name='Task-2', id=0x1039f0fe0)
+ Call stack:
| File 't2.py', line 4, in async test()
+ Awaited by:
* Task(name='Task-1', id=0x103a5e060)
+ Call stack:
| File 'taskgroups.py', line 107, in async TaskGroup.__aexit__()
| File 't2.py', line 7, in async main()

.. function:: format_call_graph(future=None, /, *, depth=1, limit=None)

Like :func:`print_call_graph`, but returns a string.
If *future* is ``None`` and there's no current task,
the function returns an empty string.


.. function:: capture_call_graph(future=None, /, *, depth=1, limit=None)

Capture the async call graph for the current task or the provided
:class:`Task` or :class:`Future`.

The function receives an optional *future* argument.
If not passed, the current running task will be used. If there's no
current task, the function returns ``None``.

If the function is called on *the current task*, the optional
keyword-only *depth* argument can be used to skip the specified
number of frames from top of the stack.

Returns a ``FutureCallGraph`` data class object:

* ``FutureCallGraph(future, call_stack, awaited_by)``

Where *future* is a reference to a :class:`Future` or
a :class:`Task` (or their subclasses.)

``call_stack`` is a tuple of ``FrameCallGraphEntry`` objects.

``awaited_by`` is a tuple of ``FutureCallGraph`` objects.

* ``FrameCallGraphEntry(frame)``

Where *frame* is a frame object of a regular Python function
in the call stack.


Low level utility functions
===========================

To introspect an async call graph asyncio requires cooperation from
control flow structures, such as :func:`shield` or :class:`TaskGroup`.
Any time an intermediate :class:`Future` object with low-level APIs like
:meth:`Future.add_done_callback() <asyncio.Future.add_done_callback>` is
involved, the following two functions should be used to inform asyncio
about how exactly such intermediate future objects are connected with
the tasks they wrap or control.


.. function:: future_add_to_awaited_by(future, waiter, /)

Record that *future* is awaited on by *waiter*.

Both *future* and *waiter* must be instances of
:class:`Future` or :class:`Task` or their subclasses,
otherwise the call would have no effect.

A call to ``future_add_to_awaited_by()`` must be followed by an
eventual call to the :func:`future_discard_from_awaited_by` function
with the same arguments.


.. function:: future_discard_from_awaited_by(future, waiter, /)

Record that *future* is no longer awaited on by *waiter*.

Both *future* and *waiter* must be instances of
:class:`Future` or :class:`Task` or their subclasses, otherwise
the call would have no effect.
1 change: 1 addition & 0 deletions Doc/library/asyncio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ You can experiment with an ``asyncio`` concurrent context in the :term:`REPL`:
asyncio-subprocess.rst
asyncio-queue.rst
asyncio-exceptions.rst
asyncio-graph.rst

.. toctree::
:caption: Low-level APIs
Expand Down
31 changes: 14 additions & 17 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ the following command can be used to display the disassembly of
>>> dis.dis(myfunc)
2 RESUME 0
<BLANKLINE>
3 LOAD_GLOBAL 0 (len)
PUSH_NULL
3 LOAD_GLOBAL 1 (len + NULL)
LOAD_FAST 0 (alist)
CALL 1
RETURN_VALUE
Expand Down Expand Up @@ -208,7 +207,6 @@ Example:
...
RESUME
LOAD_GLOBAL
PUSH_NULL
LOAD_FAST
CALL
RETURN_VALUE
Expand Down Expand Up @@ -1217,28 +1215,21 @@ iterations of the loop.

.. opcode:: LOAD_ATTR (namei)

Replaces ``STACK[-1]`` with ``getattr(STACK[-1], co_names[namei>>1])``.
If the low bit of ``namei`` is not set, this replaces ``STACK[-1]`` with
``getattr(STACK[-1], co_names[namei>>1])``.

.. versionchanged:: 3.12
If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` is
pushed to the stack before the attribute or unbound method respectively.

.. versionchanged:: 3.14
Reverted change from 3.12. The low bit of ``namei`` has no special meaning.


.. opcode:: LOAD_METHOD (namei)

Attempt to load a method named ``co_names[namei>>1]`` from the ``STACK[-1]`` object.
``STACK[-1]`` is popped.
If the low bit of ``namei`` is set, this will attempt to load a method named
``co_names[namei>>1]`` from the ``STACK[-1]`` object. ``STACK[-1]`` is popped.
This bytecode distinguishes two cases: if ``STACK[-1]`` has a method with the
correct name, the bytecode pushes the unbound method and ``STACK[-1]``.
``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL`
or :opcode:`CALL_KW` when calling the unbound method.
Otherwise, ``NULL`` and the object returned by
the attribute lookup are pushed.

.. versionadded:: 3.14
.. versionchanged:: 3.12
If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` is
pushed to the stack before the attribute or unbound method respectively.


.. opcode:: LOAD_SUPER_ATTR (namei)
Expand Down Expand Up @@ -1935,6 +1926,12 @@ but are replaced by real opcodes or removed before bytecode is generated.
This opcode is now a pseudo-instruction.


.. opcode:: LOAD_METHOD

Optimized unbound method lookup. Emitted as a ``LOAD_ATTR`` opcode
with a flag set in the arg.


.. _opcode_collections:

Opcode collections
Expand Down
10 changes: 10 additions & 0 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
| | f_locals | local namespace seen by |
| | | this frame |
+-----------------+-------------------+---------------------------+
| | f_generator | returns the generator or |
| | | coroutine object that |
| | | owns this frame, or |
| | | ``None`` if the frame is |
| | | of a regular function |
+-----------------+-------------------+---------------------------+
| | f_trace | tracing function for this |
| | | frame, or ``None`` |
+-----------------+-------------------+---------------------------+
Expand Down Expand Up @@ -310,6 +316,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):

Add ``__builtins__`` attribute to functions.

.. versionchanged:: next

Add ``f_generator`` attribute to frames.

.. function:: getmembers(object[, predicate])

Return all the members of an object in a list of ``(name, value)``
Expand Down
26 changes: 26 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ asyncio
reduces memory usage.
(Contributed by Kumar Aditya in :gh:`107803`.)

* :mod:`asyncio` has new utility functions for introspecting and printing
the program's call graph: :func:`asyncio.capture_call_graph` and
:func:`asyncio.print_call_graph`.
(Contributed by Yury Selivanov, Pablo Galindo Salgado, and Łukasz Langa
in :gh:`91048`.)

base64
------
Expand Down Expand Up @@ -1376,12 +1381,33 @@ Deprecated
.. include:: ../deprecations/c-api-pending-removal-in-3.15.rst

.. include:: ../deprecations/c-api-pending-removal-in-3.18.rst

.. include:: ../deprecations/c-api-pending-removal-in-future.rst

* The ``PyMonitoring_FireBranchEvent`` function is deprecated and should
be replaced with calls to :c:func:`PyMonitoring_FireBranchLeftEvent`
and :c:func:`PyMonitoring_FireBranchRightEvent`.

* The following private functions are deprecated and planned for removal in
Python 3.18:

* :c:func:`!_PyBytes_Join`: use :c:func:`PyBytes_Join`.
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
* :c:func:`!_PyDict_Pop()`: use :c:func:`PyDict_Pop`.
* :c:func:`!_PyLong_Sign()`: use :c:func:`PyLong_GetSign`.
* :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.

The `pythoncapi-compat project`_ can be used to get these new public
functions on Python 3.13 and older.

(Contributed by Victor Stinner in :gh:`128863`.)


Removed
-------

Expand Down
Loading

0 comments on commit c323e3b

Please sign in to comment.