Skip to content

Commit

Permalink
Merge branch 'main' into fix/codecs/xmlcharrefreplace-errors-126004
Browse files Browse the repository at this point in the history
  • Loading branch information
picnixz authored Jan 22, 2025
2 parents 5046358 + 1885988 commit 9df878e
Show file tree
Hide file tree
Showing 126 changed files with 16,952 additions and 18,357 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,7 @@ Lib/test/test_configparser.py @jaraco
Doc/reference/ @willingc @AA-Turner

**/*weakref* @kumaraditya303

# Colorize
Lib/_colorize.py @hugovk
Lib/test/test__colorize.py @hugovk
1 change: 1 addition & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'changes',
'glossary_search',
'lexers',
'pydoc_topics',
'pyspecific',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
Expand Down
16 changes: 16 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,16 @@
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:`!_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.
2 changes: 1 addition & 1 deletion Doc/deprecations/pending-removal-in-3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Pending removal in Python 3.16

* :mod:`sysconfig`:

* The ``~sysconfig.expand_makefile_vars`` function
* The :func:`!sysconfig.expand_makefile_vars` function
has been deprecated since Python 3.14.
Use the ``vars`` argument of :func:`sysconfig.get_paths` instead.

Expand Down
10 changes: 2 additions & 8 deletions Doc/library/__main__.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ Here is an example module that consumes the ``__main__`` namespace::
if not did_user_define_their_name():
raise ValueError('Define the variable `my_name`!')

if '__file__' in dir(__main__):
print(__main__.my_name, "found in file", __main__.__file__)
else:
print(__main__.my_name)
print(__main__.my_name)

Example usage of this module could be as follows::

Expand Down Expand Up @@ -330,7 +327,7 @@ status code 0, indicating success:
.. code-block:: shell-session
$ python start.py
Dinsdale found in file /path/to/start.py
Dinsdale
Note that importing ``__main__`` doesn't cause any issues with unintentionally
running top-level code meant for script use which is put in the
Expand Down Expand Up @@ -361,8 +358,5 @@ defined in the REPL becomes part of the ``__main__`` scope::
>>> namely.print_user_name()
Jabberwocky

Note that in this case the ``__main__`` scope doesn't contain a ``__file__``
attribute as it's interactive.

The ``__main__`` scope is used in the implementation of :mod:`pdb` and
:mod:`rlcompleter`.
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
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
6 changes: 4 additions & 2 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,10 @@ A function definition defines a user-defined function object (see section
: | `parameter_list_no_posonly`
parameter_list_no_posonly: `defparameter` ("," `defparameter`)* ["," [`parameter_list_starargs`]]
: | `parameter_list_starargs`
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," ["**" `parameter` [","]]]
: | "**" `parameter` [","]
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," [`parameter_star_kwargs`]]
: "*" ("," `defparameter`)+ ["," [`parameter_star_kwargs`]]
: | `parameter_star_kwargs`
parameter_star_kwargs: "**" `parameter` [","]
parameter: `identifier` [":" `expression`]
star_parameter: `identifier` [":" ["*"] `expression`]
defparameter: `parameter` ["=" `expression`]
Expand Down
Loading

0 comments on commit 9df878e

Please sign in to comment.