Skip to content

Commit 98d2b07

Browse files
authored
Merge branch 'main' into 95952-require-hostrunner
2 parents d9a7927 + c779f23 commit 98d2b07

File tree

15 files changed

+968
-338
lines changed

15 files changed

+968
-338
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"dnf",
66
"install",
77
"-y",
8-
"which",
9-
"zsh",
10-
"fish",
118
// For umask fix below.
129
"/usr/bin/setfacl"
1310
],

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
- name: Build CPython
131131
run: |
132132
make -j4 regen-all
133-
make regen-stdlib-module-names regen-sbom regen-unicodedata
133+
make regen-stdlib-module-names regen-sbom
134134
- name: Check for changes
135135
run: |
136136
git add -u

Lib/asyncio/__main__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import ast
33
import asyncio
4+
import asyncio.tools
45
import concurrent.futures
56
import contextvars
67
import inspect
@@ -10,9 +11,6 @@
1011
import threading
1112
import types
1213
import warnings
13-
from asyncio.tools import (TaskTableOutputFormat,
14-
display_awaited_by_tasks_table,
15-
display_awaited_by_tasks_tree)
1614

1715
from _colorize import get_theme
1816
from _pyrepl.console import InteractiveColoredConsole
@@ -155,22 +153,17 @@ def interrupt(self) -> None:
155153
"ps", help="Display a table of all pending tasks in a process"
156154
)
157155
ps.add_argument("pid", type=int, help="Process ID to inspect")
158-
formats = [fmt.value for fmt in TaskTableOutputFormat]
159-
formats_to_show = [fmt for fmt in formats
160-
if fmt != TaskTableOutputFormat.bsv.value]
161-
ps.add_argument("--format", choices=formats, default="table",
162-
metavar=f"{{{','.join(formats_to_show)}}}")
163156
pstree = subparsers.add_parser(
164157
"pstree", help="Display a tree of all pending tasks in a process"
165158
)
166159
pstree.add_argument("pid", type=int, help="Process ID to inspect")
167160
args = parser.parse_args()
168161
match args.command:
169162
case "ps":
170-
display_awaited_by_tasks_table(args.pid, format=args.format)
163+
asyncio.tools.display_awaited_by_tasks_table(args.pid)
171164
sys.exit(0)
172165
case "pstree":
173-
display_awaited_by_tasks_tree(args.pid)
166+
asyncio.tools.display_awaited_by_tasks_tree(args.pid)
174167
sys.exit(0)
175168
case None:
176169
pass # continue to the interactive shell

Lib/asyncio/tools.py

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""Tools to analyze tasks running in asyncio programs."""
22

3-
from collections import defaultdict
4-
import csv
3+
from collections import defaultdict, namedtuple
54
from itertools import count
6-
from enum import Enum, StrEnum, auto
5+
from enum import Enum
76
import sys
87
from _remote_debugging import RemoteUnwinder, FrameInfo
98

@@ -233,56 +232,18 @@ def _get_awaited_by_tasks(pid: int) -> list:
233232
sys.exit(1)
234233

235234

236-
class TaskTableOutputFormat(StrEnum):
237-
table = auto()
238-
csv = auto()
239-
bsv = auto()
240-
# 🍌SV is not just a format. It's a lifestyle. A philosophy.
241-
# https://www.youtube.com/watch?v=RrsVi1P6n0w
242-
243-
244-
def display_awaited_by_tasks_table(pid, *, format=TaskTableOutputFormat.table):
235+
def display_awaited_by_tasks_table(pid: int) -> None:
245236
"""Build and print a table of all pending tasks under `pid`."""
246237

247238
tasks = _get_awaited_by_tasks(pid)
248239
table = build_task_table(tasks)
249-
format = TaskTableOutputFormat(format)
250-
if format == TaskTableOutputFormat.table:
251-
_display_awaited_by_tasks_table(table)
252-
else:
253-
_display_awaited_by_tasks_csv(table, format=format)
254-
255-
256-
_row_header = ('tid', 'task id', 'task name', 'coroutine stack',
257-
'awaiter chain', 'awaiter name', 'awaiter id')
258-
259-
260-
def _display_awaited_by_tasks_table(table):
261-
"""Print the table in a simple tabular format."""
262-
print(_fmt_table_row(*_row_header))
263-
print('-' * 180)
240+
# Print the table in a simple tabular format
241+
print(
242+
f"{'tid':<10} {'task id':<20} {'task name':<20} {'coroutine stack':<50} {'awaiter chain':<50} {'awaiter name':<15} {'awaiter id':<15}"
243+
)
244+
print("-" * 180)
264245
for row in table:
265-
print(_fmt_table_row(*row))
266-
267-
268-
def _fmt_table_row(tid, task_id, task_name, coro_stack,
269-
awaiter_chain, awaiter_name, awaiter_id):
270-
# Format a single row for the table format
271-
return (f'{tid:<10} {task_id:<20} {task_name:<20} {coro_stack:<50} '
272-
f'{awaiter_chain:<50} {awaiter_name:<15} {awaiter_id:<15}')
273-
274-
275-
def _display_awaited_by_tasks_csv(table, *, format):
276-
"""Print the table in CSV format"""
277-
if format == TaskTableOutputFormat.csv:
278-
delimiter = ','
279-
elif format == TaskTableOutputFormat.bsv:
280-
delimiter = '\N{BANANA}'
281-
else:
282-
raise ValueError(f"Unknown output format: {format}")
283-
csv_writer = csv.writer(sys.stdout, delimiter=delimiter)
284-
csv_writer.writerow(_row_header)
285-
csv_writer.writerows(table)
246+
print(f"{row[0]:<10} {row[1]:<20} {row[2]:<20} {row[3]:<50} {row[4]:<50} {row[5]:<15} {row[6]:<15}")
286247

287248

288249
def display_awaited_by_tasks_tree(pid: int) -> None:

Lib/inspect.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,17 +1917,21 @@ def _signature_get_user_defined_method(cls, method_name, *, follow_wrapper_chain
19171917
if meth is None:
19181918
return None
19191919

1920+
# NOTE: The meth may wraps a non-user-defined callable.
1921+
# In this case, we treat the meth as non-user-defined callable too.
1922+
# (e.g. cls.__new__ generated by @warnings.deprecated)
1923+
unwrapped_meth = None
19201924
if follow_wrapper_chains:
1921-
meth = unwrap(meth, stop=(lambda m: hasattr(m, "__signature__")
1925+
unwrapped_meth = unwrap(meth, stop=(lambda m: hasattr(m, "__signature__")
19221926
or _signature_is_builtin(m)))
1923-
if isinstance(meth, _NonUserDefinedCallables):
1927+
1928+
if (isinstance(meth, _NonUserDefinedCallables)
1929+
or isinstance(unwrapped_meth, _NonUserDefinedCallables)):
19241930
# Once '__signature__' will be added to 'C'-level
19251931
# callables, this check won't be necessary
19261932
return None
19271933
if method_name != '__new__':
19281934
meth = _descriptor_get(meth, cls)
1929-
if follow_wrapper_chains:
1930-
meth = unwrap(meth, stop=lambda m: hasattr(m, "__signature__"))
19311935
return meth
19321936

19331937

Lib/test/test_compile.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,10 @@ def f():
823823
else:
824824
return "unused"
825825

826-
self.assertEqual(f.__code__.co_consts,
827-
(f.__doc__, "used"))
826+
if f.__doc__ is None:
827+
self.assertEqual(f.__code__.co_consts, (True, "used"))
828+
else:
829+
self.assertEqual(f.__code__.co_consts, (f.__doc__, "used"))
828830

829831
@support.cpython_only
830832
def test_remove_unused_consts_no_docstring(self):
@@ -869,7 +871,11 @@ def test_strip_unused_None(self):
869871
def f1():
870872
"docstring"
871873
return 42
872-
self.assertEqual(f1.__code__.co_consts, (f1.__doc__,))
874+
875+
if f1.__doc__ is None:
876+
self.assertEqual(f1.__code__.co_consts, (42,))
877+
else:
878+
self.assertEqual(f1.__code__.co_consts, (f1.__doc__,))
873879

874880
# This is a regression test for a CPython specific peephole optimizer
875881
# implementation bug present in a few releases. It's assertion verifies

0 commit comments

Comments
 (0)