Skip to content

Commit 4b1bc78

Browse files
authored
Merge branch 'main' into hypothesis_timeout
2 parents c31ded4 + 8783cec commit 4b1bc78

File tree

16 files changed

+110
-23
lines changed

16 files changed

+110
-23
lines changed

Doc/c-api/arg.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ Building values
669669
``L`` (:class:`int`) [long long]
670670
Convert a C :c:expr:`long long` to a Python integer object.
671671
672+
.. _capi-py-buildvalue-format-K:
673+
672674
``K`` (:class:`int`) [unsigned long long]
673675
Convert a C :c:expr:`unsigned long long` to a Python integer object.
674676

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@ although there is currently no date scheduled for their removal.
153153
:class:`~xml.etree.ElementTree.Element` is deprecated. In a future release it
154154
will always return ``True``. Prefer explicit ``len(elem)`` or
155155
``elem is not None`` tests instead.
156+
157+
* :func:`sys._clear_type_cache` is deprecated:
158+
use :func:`sys._clear_internal_caches` instead.

Doc/library/webbrowser.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ If the environment variable :envvar:`BROWSER` exists, it is interpreted as the
2424
:data:`os.pathsep`-separated list of browsers to try ahead of the platform
2525
defaults. When the value of a list part contains the string ``%s``, then it is
2626
interpreted as a literal browser command line to be used with the argument URL
27-
substituted for ``%s``; if the part does not contain ``%s``, it is simply
28-
interpreted as the name of the browser to launch. [1]_
27+
substituted for ``%s``; if the value is a single word that refers to one of the
28+
already registered browsers this browser is added to the front of the search list;
29+
if the part does not contain ``%s``, it is simply interpreted as the name of the
30+
browser to launch. [1]_
31+
32+
.. versionchanged:: next
33+
34+
The :envvar:`BROWSER` variable can now also be used to reorder the list of
35+
platform defaults. This is particularly useful on macOS where the platform
36+
defaults do not refer to command-line tools on :envvar:`PATH`.
37+
2938

3039
For non-Unix platforms, or when a remote browser is available on Unix, the
3140
controlling process will not wait for the user to finish with the browser, but

Doc/whatsnew/3.14.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,9 @@ sys
12461246
* On FreeBSD, :data:`sys.platform` doesn't contain the major version anymore.
12471247
It is always ``'freebsd'``, instead of ``'freebsd13'`` or ``'freebsd14'``.
12481248

1249+
* Raise :exc:`DeprecationWarning` for :func:`sys._clear_type_cache`. This
1250+
function was deprecated in Python 3.13 but it didn't raise a runtime warning.
1251+
12491252

12501253
sys.monitoring
12511254
--------------
@@ -1421,6 +1424,17 @@ uuid
14211424
(Contributed by Simon Legner in :gh:`131236`.)
14221425

14231426

1427+
webbrowser
1428+
----------
1429+
1430+
* Names in the :envvar:`BROWSER` environment variable can now refer to already
1431+
registered browsers for the :mod:`webbrowser` module, instead of always
1432+
generating a new browser command.
1433+
1434+
This makes it possible to set :envvar:`BROWSER` to the value of one of the
1435+
supported browsers on macOS.
1436+
1437+
14241438
zipinfo
14251439
-------
14261440

Lib/test/support/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,8 +1940,9 @@ def missing_compiler_executable(cmd_names=[]):
19401940
missing.
19411941
19421942
"""
1943-
from setuptools._distutils import ccompiler, sysconfig, spawn
1943+
from setuptools._distutils import ccompiler, sysconfig
19441944
from setuptools import errors
1945+
import shutil
19451946

19461947
compiler = ccompiler.new_compiler()
19471948
sysconfig.customize_compiler(compiler)
@@ -1960,7 +1961,7 @@ def missing_compiler_executable(cmd_names=[]):
19601961
"the '%s' executable is not configured" % name
19611962
elif not cmd:
19621963
continue
1963-
if spawn.find_executable(cmd[0]) is None:
1964+
if shutil.which(cmd[0]) is None:
19641965
return cmd[0]
19651966

19661967

Lib/test/test_cmd_line.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tempfile
1010
import textwrap
1111
import unittest
12+
import warnings
1213
from test import support
1314
from test.support import os_helper
1415
from test.support import force_not_colorized
@@ -936,14 +937,20 @@ def test_python_asyncio_debug(self):
936937
@unittest.skipUnless(sysconfig.get_config_var('Py_TRACE_REFS'), "Requires --with-trace-refs build option")
937938
def test_python_dump_refs(self):
938939
code = 'import sys; sys._clear_type_cache()'
939-
rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFS='1')
940+
# TODO: Remove warnings context manager once sys._clear_type_cache is removed
941+
with warnings.catch_warnings():
942+
warnings.simplefilter("ignore", DeprecationWarning)
943+
rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFS='1')
940944
self.assertEqual(rc, 0)
941945

942946
@unittest.skipUnless(sysconfig.get_config_var('Py_TRACE_REFS'), "Requires --with-trace-refs build option")
943947
def test_python_dump_refs_file(self):
944948
with tempfile.NamedTemporaryFile() as dump_file:
945949
code = 'import sys; sys._clear_type_cache()'
946-
rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFSFILE=dump_file.name)
950+
# TODO: Remove warnings context manager once sys._clear_type_cache is removed
951+
with warnings.catch_warnings():
952+
warnings.simplefilter("ignore", DeprecationWarning)
953+
rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFSFILE=dump_file.name)
947954
self.assertEqual(rc, 0)
948955
with open(dump_file.name, 'r') as file:
949956
contents = file.read()

Lib/test/test_remote_pdb.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
from pdb import _PdbServer, _PdbClient
2121

2222

23+
@contextmanager
24+
def kill_on_error(proc):
25+
"""Context manager killing the subprocess if a Python exception is raised."""
26+
with proc:
27+
try:
28+
yield proc
29+
except:
30+
proc.kill()
31+
raise
32+
33+
2334
class MockSocketFile:
2435
"""Mock socket file for testing _PdbServer without actual socket connections."""
2536

@@ -360,7 +371,7 @@ def test_connect_and_basic_commands(self):
360371
self._create_script()
361372
process, client_file = self._connect_and_get_client_file()
362373

363-
with process:
374+
with kill_on_error(process):
364375
# We should receive initial data from the debugger
365376
data = client_file.readline()
366377
initial_data = json.loads(data.decode())
@@ -413,7 +424,7 @@ def test_breakpoints(self):
413424
"""Test setting and hitting breakpoints."""
414425
self._create_script()
415426
process, client_file = self._connect_and_get_client_file()
416-
with process:
427+
with kill_on_error(process):
417428
# Skip initial messages until we get to the prompt
418429
self._read_until_prompt(client_file)
419430

@@ -451,6 +462,8 @@ def test_breakpoints(self):
451462
self.assertIn("Function returned: 42", stdout)
452463
self.assertEqual(process.returncode, 0)
453464

465+
# gh-132912: The test fails randomly
466+
@unittest.skipIf(True, "flaky test")
454467
def test_keyboard_interrupt(self):
455468
"""Test that sending keyboard interrupt breaks into pdb."""
456469
synchronizer_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -489,8 +502,7 @@ def bar():
489502
self._create_script(script=script)
490503
process, client_file = self._connect_and_get_client_file()
491504

492-
with process:
493-
505+
with kill_on_error(process):
494506
# Skip initial messages until we get to the prompt
495507
self._read_until_prompt(client_file)
496508

@@ -520,7 +532,7 @@ def test_handle_eof(self):
520532
self._create_script()
521533
process, client_file = self._connect_and_get_client_file()
522534

523-
with process:
535+
with kill_on_error(process):
524536
# Skip initial messages until we get to the prompt
525537
self._read_until_prompt(client_file)
526538

@@ -568,7 +580,7 @@ def run_test():
568580
self._create_script(script=script)
569581
process, client_file = self._connect_and_get_client_file()
570582

571-
with process:
583+
with kill_on_error(process):
572584
# First message should be an error about protocol version mismatch
573585
data = client_file.readline()
574586
message = json.loads(data.decode())
@@ -591,7 +603,7 @@ def test_help_system(self):
591603
self._create_script()
592604
process, client_file = self._connect_and_get_client_file()
593605

594-
with process:
606+
with kill_on_error(process):
595607
# Skip initial messages until we get to the prompt
596608
self._read_until_prompt(client_file)
597609

@@ -630,7 +642,7 @@ def test_multi_line_commands(self):
630642
self._create_script()
631643
process, client_file = self._connect_and_get_client_file()
632644

633-
with process:
645+
with kill_on_error(process):
634646
# Skip initial messages until we get to the prompt
635647
self._read_until_prompt(client_file)
636648

Lib/test/test_sys.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,9 @@ def test_sys_getwindowsversion_no_instantiation(self):
891891

892892
@test.support.cpython_only
893893
def test_clear_type_cache(self):
894-
sys._clear_type_cache()
894+
with self.assertWarnsRegex(DeprecationWarning,
895+
r"sys\._clear_type_cache\(\) is deprecated.*"):
896+
sys._clear_type_cache()
895897

896898
@force_not_colorized
897899
@support.requires_subprocess()

Lib/test/test_type_cache.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""" Tests for the internal type cache in CPython. """
2-
import unittest
32
import dis
3+
import unittest
4+
import warnings
45
from test import support
56
from test.support import import_helper, requires_specialization, requires_specialization_ft
67
try:
@@ -16,6 +17,10 @@
1617
type_assign_version = _testcapi.type_assign_version
1718
type_modified = _testcapi.type_modified
1819

20+
def clear_type_cache():
21+
with warnings.catch_warnings():
22+
warnings.simplefilter("ignore", DeprecationWarning)
23+
_clear_type_cache()
1924

2025
@support.cpython_only
2126
@unittest.skipIf(_clear_type_cache is None, "requires sys._clear_type_cache")
@@ -38,7 +43,7 @@ def test_tp_version_tag_unique(self):
3843
append_result = all_version_tags.append
3944
assertNotEqual = self.assertNotEqual
4045
for _ in range(30):
41-
_clear_type_cache()
46+
clear_type_cache()
4247
X = type('Y', (), {})
4348
X.x = 1
4449
X.x
@@ -78,7 +83,7 @@ class C:
7883
new_version = type_get_version(C)
7984
self.assertEqual(new_version, orig_version + 5)
8085

81-
_clear_type_cache()
86+
clear_type_cache()
8287

8388
def test_per_class_limit(self):
8489
class C:
@@ -112,7 +117,7 @@ class HolderSub(Holder):
112117
@support.cpython_only
113118
class TypeCacheWithSpecializationTests(unittest.TestCase):
114119
def tearDown(self):
115-
_clear_type_cache()
120+
clear_type_cache()
116121

117122
def _assign_valid_version_or_skip(self, type_):
118123
type_modified(type_)

Lib/webbrowser.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ def register_standard_browsers():
482482

483483
if sys.platform == 'darwin':
484484
register("MacOSX", None, MacOSXOSAScript('default'))
485-
register("chrome", None, MacOSXOSAScript('chrome'))
485+
register("chrome", None, MacOSXOSAScript('google chrome'))
486486
register("firefox", None, MacOSXOSAScript('firefox'))
487487
register("safari", None, MacOSXOSAScript('safari'))
488-
# OS X can use below Unix support (but we prefer using the OS X
488+
# macOS can use below Unix support (but we prefer using the macOS
489489
# specific stuff)
490490

491491
if sys.platform == "ios":
@@ -559,6 +559,19 @@ def register_standard_browsers():
559559
# Treat choices in same way as if passed into get() but do register
560560
# and prepend to _tryorder
561561
for cmdline in userchoices:
562+
if all(x not in cmdline for x in " \t"):
563+
# Assume this is the name of a registered command, use
564+
# that unless it is a GenericBrowser.
565+
try:
566+
command = _browsers[cmdline.lower()]
567+
except KeyError:
568+
pass
569+
570+
else:
571+
if not isinstance(command[1], GenericBrowser):
572+
_tryorder.insert(0, cmdline.lower())
573+
continue
574+
562575
if cmdline != '':
563576
cmd = _synthesize(cmdline, preferred=True)
564577
if cmd[1] is None:

0 commit comments

Comments
 (0)