Skip to content

Commit 9df878e

Browse files
authored
Merge branch 'main' into fix/codecs/xmlcharrefreplace-errors-126004
2 parents 5046358 + 1885988 commit 9df878e

File tree

126 files changed

+16952
-18357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+16952
-18357
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,7 @@ Lib/test/test_configparser.py @jaraco
304304
Doc/reference/ @willingc @AA-Turner
305305

306306
**/*weakref* @kumaraditya303
307+
308+
# Colorize
309+
Lib/_colorize.py @hugovk
310+
Lib/test/test__colorize.py @hugovk

Doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'changes',
2929
'glossary_search',
3030
'lexers',
31+
'pydoc_topics',
3132
'pyspecific',
3233
'sphinx.ext.coverage',
3334
'sphinx.ext.doctest',
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Pending removal in Python 3.18
2+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3+
4+
* Deprecated private functions (:gh:`128863`):
5+
6+
* :c:func:`!_PyBytes_Join`: use :c:func:`PyBytes_Join`.
7+
* :c:func:`!_PyDict_GetItemStringWithError`: use :c:func:`PyDict_GetItemStringRef`.
8+
* :c:func:`!_PyDict_Pop()`: :c:func:`PyDict_Pop`.
9+
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
10+
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
11+
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
12+
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.
13+
14+
The `pythoncapi-compat project
15+
<https://github.com/python/pythoncapi-compat/>`__ can be used to get these
16+
new public functions on Python 3.13 and older.

Doc/deprecations/pending-removal-in-3.16.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Pending removal in Python 3.16
8282

8383
* :mod:`sysconfig`:
8484

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

Doc/library/__main__.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,7 @@ Here is an example module that consumes the ``__main__`` namespace::
292292
if not did_user_define_their_name():
293293
raise ValueError('Define the variable `my_name`!')
294294

295-
if '__file__' in dir(__main__):
296-
print(__main__.my_name, "found in file", __main__.__file__)
297-
else:
298-
print(__main__.my_name)
295+
print(__main__.my_name)
299296

300297
Example usage of this module could be as follows::
301298

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

364-
Note that in this case the ``__main__`` scope doesn't contain a ``__file__``
365-
attribute as it's interactive.
366-
367361
The ``__main__`` scope is used in the implementation of :mod:`pdb` and
368362
:mod:`rlcompleter`.

Doc/library/asyncio-graph.rst

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
.. currentmodule:: asyncio
2+
3+
4+
.. _asyncio-graph:
5+
6+
========================
7+
Call Graph Introspection
8+
========================
9+
10+
**Source code:** :source:`Lib/asyncio/graph.py`
11+
12+
-------------------------------------
13+
14+
asyncio has powerful runtime call graph introspection utilities
15+
to trace the entire call graph of a running *coroutine* or *task*, or
16+
a suspended *future*. These utilities and the underlying machinery
17+
can be used from within a Python program or by external profilers
18+
and debuggers.
19+
20+
.. versionadded:: next
21+
22+
23+
.. function:: print_call_graph(future=None, /, *, file=None, depth=1, limit=None)
24+
25+
Print the async call graph for the current task or the provided
26+
:class:`Task` or :class:`Future`.
27+
28+
This function prints entries starting from the top frame and going
29+
down towards the invocation point.
30+
31+
The function receives an optional *future* argument.
32+
If not passed, the current running task will be used.
33+
34+
If the function is called on *the current task*, the optional
35+
keyword-only *depth* argument can be used to skip the specified
36+
number of frames from top of the stack.
37+
38+
If the optional keyword-only *limit* argument is provided, each call stack
39+
in the resulting graph is truncated to include at most ``abs(limit)``
40+
entries. If *limit* is positive, the entries left are the closest to
41+
the invocation point. If *limit* is negative, the topmost entries are
42+
left. If *limit* is omitted or ``None``, all entries are present.
43+
If *limit* is ``0``, the call stack is not printed at all, only
44+
"awaited by" information is printed.
45+
46+
If *file* is omitted or ``None``, the function will print
47+
to :data:`sys.stdout`.
48+
49+
**Example:**
50+
51+
The following Python code:
52+
53+
.. code-block:: python
54+
55+
import asyncio
56+
57+
async def test():
58+
asyncio.print_call_graph()
59+
60+
async def main():
61+
async with asyncio.TaskGroup() as g:
62+
g.create_task(test())
63+
64+
asyncio.run(main())
65+
66+
will print::
67+
68+
* Task(name='Task-2', id=0x1039f0fe0)
69+
+ Call stack:
70+
| File 't2.py', line 4, in async test()
71+
+ Awaited by:
72+
* Task(name='Task-1', id=0x103a5e060)
73+
+ Call stack:
74+
| File 'taskgroups.py', line 107, in async TaskGroup.__aexit__()
75+
| File 't2.py', line 7, in async main()
76+
77+
.. function:: format_call_graph(future=None, /, *, depth=1, limit=None)
78+
79+
Like :func:`print_call_graph`, but returns a string.
80+
If *future* is ``None`` and there's no current task,
81+
the function returns an empty string.
82+
83+
84+
.. function:: capture_call_graph(future=None, /, *, depth=1, limit=None)
85+
86+
Capture the async call graph for the current task or the provided
87+
:class:`Task` or :class:`Future`.
88+
89+
The function receives an optional *future* argument.
90+
If not passed, the current running task will be used. If there's no
91+
current task, the function returns ``None``.
92+
93+
If the function is called on *the current task*, the optional
94+
keyword-only *depth* argument can be used to skip the specified
95+
number of frames from top of the stack.
96+
97+
Returns a ``FutureCallGraph`` data class object:
98+
99+
* ``FutureCallGraph(future, call_stack, awaited_by)``
100+
101+
Where *future* is a reference to a :class:`Future` or
102+
a :class:`Task` (or their subclasses.)
103+
104+
``call_stack`` is a tuple of ``FrameCallGraphEntry`` objects.
105+
106+
``awaited_by`` is a tuple of ``FutureCallGraph`` objects.
107+
108+
* ``FrameCallGraphEntry(frame)``
109+
110+
Where *frame* is a frame object of a regular Python function
111+
in the call stack.
112+
113+
114+
Low level utility functions
115+
===========================
116+
117+
To introspect an async call graph asyncio requires cooperation from
118+
control flow structures, such as :func:`shield` or :class:`TaskGroup`.
119+
Any time an intermediate :class:`Future` object with low-level APIs like
120+
:meth:`Future.add_done_callback() <asyncio.Future.add_done_callback>` is
121+
involved, the following two functions should be used to inform asyncio
122+
about how exactly such intermediate future objects are connected with
123+
the tasks they wrap or control.
124+
125+
126+
.. function:: future_add_to_awaited_by(future, waiter, /)
127+
128+
Record that *future* is awaited on by *waiter*.
129+
130+
Both *future* and *waiter* must be instances of
131+
:class:`Future` or :class:`Task` or their subclasses,
132+
otherwise the call would have no effect.
133+
134+
A call to ``future_add_to_awaited_by()`` must be followed by an
135+
eventual call to the :func:`future_discard_from_awaited_by` function
136+
with the same arguments.
137+
138+
139+
.. function:: future_discard_from_awaited_by(future, waiter, /)
140+
141+
Record that *future* is no longer awaited on by *waiter*.
142+
143+
Both *future* and *waiter* must be instances of
144+
:class:`Future` or :class:`Task` or their subclasses, otherwise
145+
the call would have no effect.

Doc/library/asyncio.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ You can experiment with an ``asyncio`` concurrent context in the :term:`REPL`:
9999
asyncio-subprocess.rst
100100
asyncio-queue.rst
101101
asyncio-exceptions.rst
102+
asyncio-graph.rst
102103

103104
.. toctree::
104105
:caption: Low-level APIs

Doc/library/inspect.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
150150
| | f_locals | local namespace seen by |
151151
| | | this frame |
152152
+-----------------+-------------------+---------------------------+
153+
| | f_generator | returns the generator or |
154+
| | | coroutine object that |
155+
| | | owns this frame, or |
156+
| | | ``None`` if the frame is |
157+
| | | of a regular function |
158+
+-----------------+-------------------+---------------------------+
153159
| | f_trace | tracing function for this |
154160
| | | frame, or ``None`` |
155161
+-----------------+-------------------+---------------------------+
@@ -310,6 +316,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
310316

311317
Add ``__builtins__`` attribute to functions.
312318

319+
.. versionchanged:: next
320+
321+
Add ``f_generator`` attribute to frames.
322+
313323
.. function:: getmembers(object[, predicate])
314324

315325
Return all the members of an object in a list of ``(name, value)``

Doc/reference/compound_stmts.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,10 @@ A function definition defines a user-defined function object (see section
12171217
: | `parameter_list_no_posonly`
12181218
parameter_list_no_posonly: `defparameter` ("," `defparameter`)* ["," [`parameter_list_starargs`]]
12191219
: | `parameter_list_starargs`
1220-
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," ["**" `parameter` [","]]]
1221-
: | "**" `parameter` [","]
1220+
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," [`parameter_star_kwargs`]]
1221+
: "*" ("," `defparameter`)+ ["," [`parameter_star_kwargs`]]
1222+
: | `parameter_star_kwargs`
1223+
parameter_star_kwargs: "**" `parameter` [","]
12221224
parameter: `identifier` [":" `expression`]
12231225
star_parameter: `identifier` [":" ["*"] `expression`]
12241226
defparameter: `parameter` ["=" `expression`]

0 commit comments

Comments
 (0)