Skip to content

Commit 58c7a39

Browse files
committed
Merge in the main branch
2 parents 696f1d0 + 149bddc commit 58c7a39

File tree

79 files changed

+3357
-1931
lines changed

Some content is hidden

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

79 files changed

+3357
-1931
lines changed

Android/android.py

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@
5050
+ (".bat" if os.name == "nt" else "")
5151
)
5252

53-
logcat_started = False
53+
# Whether we've seen any output from Python yet.
54+
python_started = False
55+
56+
# Buffer for verbose output which will be displayed only if a test fails and
57+
# there has been no output from Python.
58+
hidden_output = []
59+
60+
61+
def log_verbose(context, line, stream=sys.stdout):
62+
if context.verbose:
63+
stream.write(line)
64+
else:
65+
hidden_output.append((stream, line))
5466

5567

5668
def delete_glob(pattern):
@@ -118,7 +130,7 @@ def android_env(host):
118130
env_script = ANDROID_DIR / "android-env.sh"
119131
env_output = subprocess.run(
120132
f"set -eu; "
121-
f"export HOST={host}; "
133+
f"HOST={host}; "
122134
f"PREFIX={prefix}; "
123135
f". {env_script}; "
124136
f"export",
@@ -453,17 +465,19 @@ async def logcat_task(context, initial_devices):
453465

454466
# `--pid` requires API level 24 or higher.
455467
args = [adb, "-s", serial, "logcat", "--pid", pid, "--format", "tag"]
456-
hidden_output = []
468+
logcat_started = False
457469
async with async_process(
458470
*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
459471
) as process:
460472
while line := (await process.stdout.readline()).decode(*DECODE_ARGS):
461473
if match := re.fullmatch(r"([A-Z])/(.*)", line, re.DOTALL):
474+
logcat_started = True
462475
level, message = match.groups()
463476
else:
464-
# If the regex doesn't match, this is probably the second or
465-
# subsequent line of a multi-line message. Python won't produce
466-
# such messages, but other components might.
477+
# If the regex doesn't match, this is either a logcat startup
478+
# error, or the second or subsequent line of a multi-line
479+
# message. Python won't produce multi-line messages, but other
480+
# components might.
467481
level, message = None, line
468482

469483
# Exclude high-volume messages which are rarely useful.
@@ -483,25 +497,22 @@ async def logcat_task(context, initial_devices):
483497
# tag indicators from Python's stdout and stderr.
484498
for prefix in ["python.stdout: ", "python.stderr: "]:
485499
if message.startswith(prefix):
486-
global logcat_started
487-
logcat_started = True
500+
global python_started
501+
python_started = True
488502
stream.write(message.removeprefix(prefix))
489503
break
490504
else:
491-
if context.verbose:
492-
# Non-Python messages add a lot of noise, but they may
493-
# sometimes help explain a failure.
494-
stream.write(line)
495-
else:
496-
hidden_output.append(line)
505+
# Non-Python messages add a lot of noise, but they may
506+
# sometimes help explain a failure.
507+
log_verbose(context, line, stream)
497508

498509
# If the device disconnects while logcat is running, which always
499510
# happens in --managed mode, some versions of adb return non-zero.
500511
# Distinguish this from a logcat startup error by checking whether we've
501-
# received a message from Python yet.
512+
# received any logcat messages yet.
502513
status = await wait_for(process.wait(), timeout=1)
503514
if status != 0 and not logcat_started:
504-
raise CalledProcessError(status, args, "".join(hidden_output))
515+
raise CalledProcessError(status, args)
505516

506517

507518
def stop_app(serial):
@@ -516,16 +527,6 @@ async def gradle_task(context):
516527
task_prefix = "connected"
517528
env["ANDROID_SERIAL"] = context.connected
518529

519-
hidden_output = []
520-
521-
def log(line):
522-
# Gradle may take several minutes to install SDK packages, so it's worth
523-
# showing those messages even in non-verbose mode.
524-
if context.verbose or line.startswith('Preparing "Install'):
525-
sys.stdout.write(line)
526-
else:
527-
hidden_output.append(line)
528-
529530
if context.command:
530531
mode = "-c"
531532
module = context.command
@@ -550,27 +551,27 @@ def log(line):
550551
]
551552
if context.verbose >= 2:
552553
args.append("--info")
553-
log("> " + join_command(args))
554+
log_verbose(context, f"> {join_command(args)}\n")
554555

555556
try:
556557
async with async_process(
557558
*args, cwd=TESTBED_DIR, env=env,
558559
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
559560
) as process:
560561
while line := (await process.stdout.readline()).decode(*DECODE_ARGS):
561-
log(line)
562+
# Gradle may take several minutes to install SDK packages, so
563+
# it's worth showing those messages even in non-verbose mode.
564+
if line.startswith('Preparing "Install'):
565+
sys.stdout.write(line)
566+
else:
567+
log_verbose(context, line)
562568

563569
status = await wait_for(process.wait(), timeout=1)
564570
if status == 0:
565571
exit(0)
566572
else:
567573
raise CalledProcessError(status, args)
568574
finally:
569-
# If logcat never started, then something has gone badly wrong, so the
570-
# user probably wants to see the Gradle output even in non-verbose mode.
571-
if hidden_output and not logcat_started:
572-
sys.stdout.write("".join(hidden_output))
573-
574575
# Gradle does not stop the tests when interrupted.
575576
if context.connected:
576577
stop_app(context.connected)
@@ -600,6 +601,12 @@ async def run_testbed(context):
600601
except* MySystemExit as e:
601602
raise SystemExit(*e.exceptions[0].args) from None
602603
except* CalledProcessError as e:
604+
# If Python produced no output, then the user probably wants to see the
605+
# verbose output to explain why the test failed.
606+
if not python_started:
607+
for stream, line in hidden_output:
608+
stream.write(line)
609+
603610
# Extract it from the ExceptionGroup so it can be handled by `main`.
604611
raise e.exceptions[0]
605612

Doc/c-api/init.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,12 @@ is resumed, and its locks reacquired. This means the critical section API
23062306
provides weaker guarantees than traditional locks -- they are useful because
23072307
their behavior is similar to the :term:`GIL`.
23082308
2309+
Variants that accept :c:type:`PyMutex` pointers rather than Python objects are also
2310+
available. Use these variants to start a critical section in a situation where
2311+
there is no :c:type:`PyObject` -- for example, when working with a C type that
2312+
does not extend or wrap :c:type:`PyObject` but still needs to call into the C
2313+
API in a manner that might lead to deadlocks.
2314+
23092315
The functions and structs used by the macros are exposed for cases
23102316
where C macros are not available. They should only be used as in the
23112317
given macro expansions. Note that the sizes and contents of the structures may
@@ -2351,6 +2357,23 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
23512357
23522358
.. versionadded:: 3.13
23532359
2360+
.. c:macro:: Py_BEGIN_CRITICAL_SECTION_MUTEX(m)
2361+
2362+
Locks the mutex *m* and begins a critical section.
2363+
2364+
In the free-threaded build, this macro expands to::
2365+
2366+
{
2367+
PyCriticalSection _py_cs;
2368+
PyCriticalSection_BeginMutex(&_py_cs, m)
2369+
2370+
Note that unlike :c:macro:`Py_BEGIN_CRITICAL_SECTION`, there is no cast for
2371+
the argument of the macro - it must be a :c:type:`PyMutex` pointer.
2372+
2373+
On the default build, this macro expands to ``{``.
2374+
2375+
.. versionadded:: next
2376+
23542377
.. c:macro:: Py_END_CRITICAL_SECTION()
23552378
23562379
Ends the critical section and releases the per-object lock.
@@ -2380,6 +2403,23 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
23802403
23812404
.. versionadded:: 3.13
23822405
2406+
.. c:macro:: Py_BEGIN_CRITICAL_SECTION2_MUTEX(m1, m2)
2407+
2408+
Locks the mutexes *m1* and *m2* and begins a critical section.
2409+
2410+
In the free-threaded build, this macro expands to::
2411+
2412+
{
2413+
PyCriticalSection2 _py_cs2;
2414+
PyCriticalSection2_BeginMutex(&_py_cs2, m1, m2)
2415+
2416+
Note that unlike :c:macro:`Py_BEGIN_CRITICAL_SECTION2`, there is no cast for
2417+
the arguments of the macro - they must be :c:type:`PyMutex` pointers.
2418+
2419+
On the default build, this macro expands to ``{``.
2420+
2421+
.. versionadded:: next
2422+
23832423
.. c:macro:: Py_END_CRITICAL_SECTION2()
23842424
23852425
Ends the critical section and releases the per-object locks.

Doc/howto/logging.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ reading the following sections. If you're ready for that, grab some of your
302302
favourite beverage and carry on.
303303

304304
If your logging needs are simple, then use the above examples to incorporate
305-
logging into your own scripts, and if you run into problems or don't
306-
understand something, please post a question on the comp.lang.python Usenet
307-
group (available at https://groups.google.com/g/comp.lang.python) and you
308-
should receive help before too long.
305+
logging into your own scripts, and if you run into problems or don't understand
306+
something, please post a question in the Help category of the `Python
307+
discussion forum <https://discuss.python.org/c/help/7>`_ and you should receive
308+
help before too long.
309309

310310
Still here? You can carry on reading the next few sections, which provide a
311311
slightly more advanced/in-depth tutorial than the basic one above. After that,

Doc/library/enum.rst

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,16 +504,31 @@ Data Types
504504

505505
.. class:: StrEnum
506506

507-
``StrEnum`` is the same as :class:`Enum`, but its members are also strings and can be used
508-
in most of the same places that a string can be used. The result of any string
509-
operation performed on or with a *StrEnum* member is not part of the enumeration.
507+
*StrEnum* is the same as :class:`Enum`, but its members are also strings and
508+
can be used in most of the same places that a string can be used. The result
509+
of any string operation performed on or with a *StrEnum* member is not part
510+
of the enumeration.
511+
512+
>>> from enum import StrEnum, auto
513+
>>> class Color(StrEnum):
514+
... RED = 'r'
515+
... GREEN = 'g'
516+
... BLUE = 'b'
517+
... UNKNOWN = auto()
518+
...
519+
>>> Color.RED
520+
<Color.RED: 'r'>
521+
>>> Color.UNKNOWN
522+
<Color.UNKNOWN: 'unknown'>
523+
>>> str(Color.UNKNOWN)
524+
'unknown'
510525

511526
.. note::
512527

513528
There are places in the stdlib that check for an exact :class:`str`
514529
instead of a :class:`str` subclass (i.e. ``type(unknown) == str``
515530
instead of ``isinstance(unknown, str)``), and in those locations you
516-
will need to use ``str(StrEnum.member)``.
531+
will need to use ``str(MyStrEnum.MY_MEMBER)``.
517532

518533
.. note::
519534

Doc/library/os.path.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ the :mod:`glob` module.)
6464
Accepts a :term:`path-like object`.
6565

6666

67-
.. function:: basename(path)
67+
.. function:: basename(path, /)
6868

6969
Return the base name of pathname *path*. This is the second element of the
7070
pair returned by passing *path* to the function :func:`split`. Note that
@@ -118,7 +118,7 @@ the :mod:`glob` module.)
118118
Accepts a :term:`path-like object`.
119119

120120

121-
.. function:: dirname(path)
121+
.. function:: dirname(path, /)
122122

123123
Return the directory name of pathname *path*. This is the first element of
124124
the pair returned by passing *path* to the function :func:`split`.
@@ -237,7 +237,7 @@ the :mod:`glob` module.)
237237
Accepts a :term:`path-like object`.
238238

239239

240-
.. function:: isabs(path)
240+
.. function:: isabs(path, /)
241241

242242
Return ``True`` if *path* is an absolute pathname. On Unix, that means it
243243
begins with a slash, on Windows that it begins with two (back)slashes, or a
@@ -261,7 +261,7 @@ the :mod:`glob` module.)
261261
Accepts a :term:`path-like object`.
262262

263263

264-
.. function:: isdir(path)
264+
.. function:: isdir(path, /)
265265

266266
Return ``True`` if *path* is an :func:`existing <exists>` directory. This
267267
follows symbolic links, so both :func:`islink` and :func:`isdir` can be true
@@ -372,7 +372,7 @@ the :mod:`glob` module.)
372372
Accepts a :term:`path-like object` for *path* and *paths*.
373373

374374

375-
.. function:: normcase(path)
375+
.. function:: normcase(path, /)
376376

377377
Normalize the case of a pathname. On Windows, convert all characters in the
378378
pathname to lowercase, and also convert forward slashes to backward slashes.
@@ -509,7 +509,7 @@ the :mod:`glob` module.)
509509
Added Windows support.
510510

511511

512-
.. function:: split(path)
512+
.. function:: split(path, /)
513513

514514
Split the pathname *path* into a pair, ``(head, tail)`` where *tail* is the
515515
last pathname component and *head* is everything leading up to that. The
@@ -525,7 +525,7 @@ the :mod:`glob` module.)
525525
Accepts a :term:`path-like object`.
526526

527527

528-
.. function:: splitdrive(path)
528+
.. function:: splitdrive(path, /)
529529

530530
Split the pathname *path* into a pair ``(drive, tail)`` where *drive* is either
531531
a mount point or the empty string. On systems which do not use drive
@@ -550,7 +550,7 @@ the :mod:`glob` module.)
550550
Accepts a :term:`path-like object`.
551551

552552

553-
.. function:: splitroot(path)
553+
.. function:: splitroot(path, /)
554554

555555
Split the pathname *path* into a 3-item tuple ``(drive, root, tail)`` where
556556
*drive* is a device name or mount point, *root* is a string of separators
@@ -583,7 +583,7 @@ the :mod:`glob` module.)
583583
.. versionadded:: 3.12
584584

585585

586-
.. function:: splitext(path)
586+
.. function:: splitext(path, /)
587587

588588
Split the pathname *path* into a pair ``(root, ext)`` such that ``root + ext ==
589589
path``, and the extension, *ext*, is empty or begins with a period and contains at

Doc/library/sys.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,8 +2191,11 @@ always available. Unless explicitly noted otherwise, all variables are read-only
21912191

21922192
.. data:: api_version
21932193

2194-
The C API version for this interpreter. Programmers may find this useful when
2195-
debugging version conflicts between Python and extension modules.
2194+
The C API version, equivalent to the C macro :c:macro:`PYTHON_API_VERSION`.
2195+
Defined for backwards compatibility.
2196+
2197+
Currently, this constant is not updated in new Python versions, and is not
2198+
useful for versioning. This may change in the future.
21962199

21972200

21982201
.. data:: version_info

Doc/library/urllib.request.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ The :mod:`urllib.request` module defines the following functions:
210210
Windows a UNC path is returned (as before), and on other platforms a
211211
:exc:`~urllib.error.URLError` is raised.
212212

213+
.. versionchanged:: 3.14
214+
The URL query and fragment components are discarded if present.
215+
213216
.. versionchanged:: 3.14
214217
The *require_scheme* and *resolve_host* parameters were added.
215218

Doc/library/zipfile.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,6 @@ The following data attributes are also available:
558558
it should be no longer than 65535 bytes. Comments longer than this will be
559559
truncated.
560560

561-
.. attribute:: ZipFile.data_offset
562-
563-
The offset to the start of ZIP data from the beginning of the file. When the
564-
:class:`ZipFile` is opened in either mode ``'w'`` or ``'x'`` and the
565-
underlying file does not support ``tell()``, the value will be ``None``
566-
instead.
567-
568-
.. versionadded:: 3.14
569561

570562
.. _path-objects:
571563

Doc/tutorial/modules.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@ module for example, you might use::
579579
from .. import formats
580580
from ..filters import equalizer
581581

582-
Note that relative imports are based on the name of the current module. Since
583-
the name of the main module is always ``"__main__"``, modules intended for use
582+
Note that relative imports are based on the name of the current module's package.
583+
Since the main module does not have a package, modules intended for use
584584
as the main module of a Python application must always use absolute imports.
585585

586586

0 commit comments

Comments
 (0)