Skip to content

Commit ad010b4

Browse files
generatedunixname1734921407115435facebook-github-bot
authored andcommitted
Import upstream CPython branch '3.14'
Summary: Python `3.14.0rc2+` (`3.14`) was **published** on 2025-09-12 13:23:03+00:00. # Commit Info Base: (`3.14.0rc2+`) - `8a767fbcb3168a48a7e909b597c070d103901b87` (commit date: 2025-09-11 09:38:14+00:00) Imported: (`3.14.0rc2+`) - `3.14` (commit date: 2025-09-12 13:23:03+00:00) # Files added ```javascript Misc/NEWS.d/next/Core_and_Builtins/2025-09-03-17-00-30.gh-issue-138479.qUxgWs.rst Misc/NEWS.d/next/Core_and_Builtins/2025-09-10-14-53-59.gh-issue-71810.ppf0J-.rst ``` Reviewed By: itamaro Differential Revision: D82374455 fbshipit-source-id: 5f6be99544fe55c7725b8246915c0a38cdc626fd
1 parent 14ce24c commit ad010b4

12 files changed

Lines changed: 211 additions & 25 deletions

File tree

Doc/howto/remote_debugging.rst

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,78 @@
33
Remote debugging attachment protocol
44
====================================
55

6+
This protocol enables external tools to attach to a running CPython process and
7+
execute Python code remotely.
8+
9+
Most platforms require elevated privileges to attach to another Python process.
10+
11+
.. _permission-requirements:
12+
13+
Permission requirements
14+
=======================
15+
16+
Attaching to a running Python process for remote debugging requires elevated
17+
privileges on most platforms. The specific requirements and troubleshooting
18+
steps depend on your operating system:
19+
20+
.. rubric:: Linux
21+
22+
The tracer process must have the ``CAP_SYS_PTRACE`` capability or equivalent
23+
privileges. You can only trace processes you own and can signal. Tracing may
24+
fail if the process is already being traced, or if it is running with
25+
set-user-ID or set-group-ID. Security modules like Yama may further restrict
26+
tracing.
27+
28+
To temporarily relax ptrace restrictions (until reboot), run:
29+
30+
``echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope``
31+
32+
.. note::
33+
34+
Disabling ``ptrace_scope`` reduces system hardening and should only be done
35+
in trusted environments.
36+
37+
If running inside a container, use ``--cap-add=SYS_PTRACE`` or
38+
``--privileged``, and run as root if needed.
39+
40+
Try re-running the command with elevated privileges:
41+
42+
``sudo -E !!``
43+
44+
45+
.. rubric:: macOS
46+
47+
To attach to another process, you typically need to run your debugging tool
48+
with elevated privileges. This can be done by using ``sudo`` or running as
49+
root.
50+
51+
Even when attaching to processes you own, macOS may block debugging unless
52+
the debugger is run with root privileges due to system security restrictions.
53+
54+
55+
.. rubric:: Windows
56+
57+
To attach to another process, you usually need to run your debugging tool
58+
with administrative privileges. Start the command prompt or terminal as
59+
Administrator.
60+
61+
Some processes may still be inaccessible even with Administrator rights,
62+
unless you have the ``SeDebugPrivilege`` privilege enabled.
63+
64+
To resolve file or folder access issues, adjust the security permissions:
65+
66+
1. Right-click the file or folder and select **Properties**.
67+
2. Go to the **Security** tab to view users and groups with access.
68+
3. Click **Edit** to modify permissions.
69+
4. Select your user account.
70+
5. In **Permissions**, check **Read** or **Full control** as needed.
71+
6. Click **Apply**, then **OK** to confirm.
72+
73+
74+
.. note::
75+
76+
Ensure you've satisfied all :ref:`permission-requirements` before proceeding.
77+
678
This section describes the low-level protocol that enables external tools to
779
inject and execute a Python script within a running CPython process.
880

Doc/library/csv.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ Dialects support the following attributes:
467467
.. attribute:: Dialect.skipinitialspace
468468

469469
When :const:`True`, spaces immediately following the *delimiter* are ignored.
470-
The default is :const:`False`.
470+
The default is :const:`False`. When combining ``delimiter=' '`` with
471+
``skipinitialspace=True``, unquoted empty fields are not allowed.
471472

472473

473474
.. attribute:: Dialect.strict
@@ -636,7 +637,7 @@ done::
636637
.. rubric:: Footnotes
637638

638639
.. [1] If ``newline=''`` is not specified, newlines embedded inside quoted fields
639-
will not be interpreted correctly, and on platforms that use ``\r\n`` linendings
640+
will not be interpreted correctly, and on platforms that use ``\r\n`` line endings
640641
on write an extra ``\r`` will be added. It should always be safe to specify
641642
``newline=''``, since the csv module does its own
642643
(:term:`universal <universal newlines>`) newline handling.

Lib/asyncio/tools.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ def _print_cycle_exception(exception: CycleFoundException):
222222
print(f"cycle: {inames}", file=sys.stderr)
223223

224224

225+
def exit_with_permission_help_text():
226+
"""
227+
Prints a message pointing to platform-specific permission help text and exits the program.
228+
This function is called when a PermissionError is encountered while trying
229+
to attach to a process.
230+
"""
231+
print(
232+
"Error: The specified process cannot be attached to due to insufficient permissions.\n"
233+
"See the Python documentation for details on required privileges and troubleshooting:\n"
234+
"https://docs.python.org/3.14/howto/remote_debugging.html#permission-requirements\n"
235+
)
236+
sys.exit(1)
237+
238+
225239
def _get_awaited_by_tasks(pid: int) -> list:
226240
try:
227241
return get_all_awaited_by(pid)
@@ -230,6 +244,8 @@ def _get_awaited_by_tasks(pid: int) -> list:
230244
e = e.__context__
231245
print(f"Error retrieving tasks: {e}")
232246
sys.exit(1)
247+
except PermissionError as e:
248+
exit_with_permission_help_text()
233249

234250

235251
def display_awaited_by_tasks_table(pid: int) -> None:

Lib/pdb.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,20 @@ def help():
35053505
"-c 'until X'"."""
35063506

35073507

3508+
def exit_with_permission_help_text():
3509+
"""
3510+
Prints a message pointing to platform-specific permission help text and exits the program.
3511+
This function is called when a PermissionError is encountered while trying
3512+
to attach to a process.
3513+
"""
3514+
print(
3515+
"Error: The specified process cannot be attached to due to insufficient permissions.\n"
3516+
"See the Python documentation for details on required privileges and troubleshooting:\n"
3517+
"https://docs.python.org/3.14/howto/remote_debugging.html#permission-requirements\n"
3518+
)
3519+
sys.exit(1)
3520+
3521+
35083522
def main():
35093523
import argparse
35103524

@@ -3538,7 +3552,10 @@ def main():
35383552
opts = parser.parse_args()
35393553
if opts.module:
35403554
parser.error("argument -m: not allowed with argument --pid")
3541-
attach(opts.pid, opts.commands)
3555+
try:
3556+
attach(opts.pid, opts.commands)
3557+
except PermissionError as e:
3558+
exit_with_permission_help_text()
35423559
return
35433560
elif opts.module:
35443561
# If a module is being debugged, we consider the arguments after "-m module" to

Lib/test/test_long.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,17 +1374,22 @@ def equivalent_python(n, length, byteorder, signed=False):
13741374
check(tests4, 'little', signed=False)
13751375

13761376
self.assertRaises(OverflowError, (256).to_bytes, 1, 'big', signed=False)
1377-
self.assertRaises(OverflowError, (256).to_bytes, 1, 'big', signed=True)
13781377
self.assertRaises(OverflowError, (256).to_bytes, 1, 'little', signed=False)
1379-
self.assertRaises(OverflowError, (256).to_bytes, 1, 'little', signed=True)
1378+
self.assertRaises(OverflowError, (128).to_bytes, 1, 'big', signed=True)
1379+
self.assertRaises(OverflowError, (128).to_bytes, 1, 'little', signed=True)
1380+
self.assertRaises(OverflowError, (-129).to_bytes, 1, 'big', signed=True)
1381+
self.assertRaises(OverflowError, (-129).to_bytes, 1, 'little', signed=True)
13801382
self.assertRaises(OverflowError, (-1).to_bytes, 2, 'big', signed=False)
13811383
self.assertRaises(OverflowError, (-1).to_bytes, 2, 'little', signed=False)
13821384
self.assertEqual((0).to_bytes(0, 'big'), b'')
1385+
self.assertEqual((0).to_bytes(0, 'big', signed=True), b'')
13831386
self.assertEqual((1).to_bytes(5, 'big'), b'\x00\x00\x00\x00\x01')
13841387
self.assertEqual((0).to_bytes(5, 'big'), b'\x00\x00\x00\x00\x00')
13851388
self.assertEqual((-1).to_bytes(5, 'big', signed=True),
13861389
b'\xff\xff\xff\xff\xff')
13871390
self.assertRaises(OverflowError, (1).to_bytes, 0, 'big')
1391+
self.assertRaises(OverflowError, (-1).to_bytes, 0, 'big', signed=True)
1392+
self.assertRaises(OverflowError, (-1).to_bytes, 0, 'little', signed=True)
13881393

13891394
# gh-98783
13901395
class SubStr(str):

Lib/test/test_remote_pdb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,9 @@ def do_integration_test(self, client_stdin):
15391539
redirect_stdout(client_stdout),
15401540
redirect_stderr(client_stderr),
15411541
unittest.mock.patch("sys.argv", ["pdb", "-p", str(process.pid)]),
1542+
unittest.mock.patch(
1543+
"pdb.exit_with_permission_help_text", side_effect=PermissionError
1544+
),
15421545
):
15431546
try:
15441547
pdb.main()

Lib/test/test_typing.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5797,6 +5797,23 @@ class A:
57975797
with self.assertRaises(TypeError):
57985798
a[int]
57995799

5800+
def test_return_non_tuple_while_unpacking(self):
5801+
# GH-138497: GenericAlias objects didn't ensure that __typing_subst__ actually
5802+
# returned a tuple
5803+
class EvilTypeVar:
5804+
__typing_is_unpacked_typevartuple__ = True
5805+
def __typing_prepare_subst__(*_):
5806+
return None # any value
5807+
def __typing_subst__(*_):
5808+
return 42 # not tuple
5809+
5810+
evil = EvilTypeVar()
5811+
# Create a dummy TypeAlias that will be given the evil generic from
5812+
# above.
5813+
type type_alias[*_] = 0
5814+
with self.assertRaisesRegex(TypeError, ".+__typing_subst__.+tuple.+int.*"):
5815+
type_alias[evil][0]
5816+
58005817

58015818
class ClassVarTests(BaseTestCase):
58025819

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash when a generic object's ``__typing_subst__`` returns an object
2+
that isn't a :class:`tuple`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Raise :exc:`OverflowError` for ``(-1).to_bytes()`` for signed conversions
2+
when bytes count is zero. Patch by Sergey B Kirpichev.

0 commit comments

Comments
 (0)