Skip to content

Commit 152594b

Browse files
Merge branch 'main' into docs/man-warnings-message
2 parents 3f65242 + 6d2b551 commit 152594b

12 files changed

Lines changed: 66 additions & 16 deletions

.github/workflows/reusable-check-html-ids.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ jobs:
2020
with:
2121
persist-credentials: false
2222
ref: ${{ github.event.pull_request.head.sha }}
23+
- name: 'Downgrade Git'
24+
# Temporarily downgrade to 2.43 until 2.55 is in the runner image,
25+
# to avoid "fatal: shallow file has changed since we read it" bug.
26+
# See https://github.com/python/cpython/issues/151365.
27+
run: |
28+
sudo apt-get install -y --allow-downgrades 'git=1:2.43.*' 'git-man=1:2.43.*'
29+
git --version
2330
- name: 'Find merge base'
2431
id: merge-base
2532
run: |

.github/workflows/reusable-context.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ jobs:
9090
|| ''
9191
}}
9292
93+
- name: 'Downgrade Git'
94+
# Temporarily downgrade to 2.43 until 2.55 is in the runner image,
95+
# to avoid "fatal: shallow file has changed since we read it" bug.
96+
# See https://github.com/python/cpython/issues/151365.
97+
if: github.event_name == 'pull_request'
98+
run: |
99+
sudo apt-get install -y --allow-downgrades 'git=1:2.43.*' 'git-man=1:2.43.*'
100+
git --version
101+
93102
# Adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721
94103
- name: Fetch commits to get branch diff
95104
if: github.event_name == 'pull_request'

.github/workflows/reusable-docs.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ jobs:
4747
&& github.event.pull_request.head.sha
4848
|| ''
4949
}}
50+
- name: 'Downgrade Git'
51+
# Temporarily downgrade to 2.43 until 2.55 is in the runner image,
52+
# to avoid "fatal: shallow file has changed since we read it" bug.
53+
# See https://github.com/python/cpython/issues/151365.
54+
if: github.event_name == 'pull_request'
55+
run: |
56+
sudo apt-get install -y --allow-downgrades 'git=1:2.43.*' 'git-man=1:2.43.*'
57+
git --version
5058
# Adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721
5159
- name: 'Fetch commits to get branch diff'
5260
if: github.event_name == 'pull_request'

Lib/shutil.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,28 @@
1818
except ImportError:
1919
_ZLIB_SUPPORTED = False
2020

21+
# bz2, lzma and compression.zstd are pure Python wrappers whose only
22+
# importable dependency that may be missing is the extension module they
23+
# wrap. Probe those extensions directly instead: it gives the same answer
24+
# without executing the wrappers, which shutil only needs when an archive
25+
# is actually created or extracted.
2126
try:
22-
import bz2
23-
del bz2
27+
import _bz2
28+
del _bz2
2429
_BZ2_SUPPORTED = True
2530
except ImportError:
2631
_BZ2_SUPPORTED = False
2732

2833
try:
29-
import lzma
30-
del lzma
34+
import _lzma
35+
del _lzma
3136
_LZMA_SUPPORTED = True
3237
except ImportError:
3338
_LZMA_SUPPORTED = False
3439

3540
try:
36-
from compression import zstd
37-
del zstd
41+
import _zstd
42+
del _zstd
3843
_ZSTD_SUPPORTED = True
3944
except ImportError:
4045
_ZSTD_SUPPORTED = False

Lib/ssl.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,6 @@ def _create_unverified_context(protocol=None, *, cert_reqs=CERT_NONE,
757757
context.check_hostname = check_hostname
758758
if cert_reqs is not None:
759759
context.verify_mode = cert_reqs
760-
if check_hostname:
761-
context.check_hostname = True
762760

763761
if keyfile and not certfile:
764762
raise ValueError("certfile must be specified")

Lib/test/support/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,3 +3465,9 @@ def skip_on_low_desktop_heap_memory_subprocess(returncode):
34653465
if returncode == STATUS_DLL_INIT_FAILED:
34663466
raise unittest.SkipTest('gh-150436: DLL init failed, likely because '
34673467
'of low desktop heap memory')
3468+
3469+
3470+
def check_immutable_type(testcase, type):
3471+
regex = r'cannot set .* attribute of immutable type'
3472+
with testcase.assertRaisesRegex(TypeError, regex):
3473+
setattr(type, 'custom_attr', 123)

Lib/test/test_decimal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import unittest
3333
import numbers
3434
import locale
35+
from test import support
3536
from test.support import (is_resource_enabled,
3637
requires_IEEE_754, requires_docstrings,
3738
check_disallow_instantiation)
@@ -5806,8 +5807,7 @@ def test_c_immutable_types(self):
58065807
)
58075808
for tp in types:
58085809
with self.subTest(tp=tp):
5809-
with self.assertRaisesRegex(TypeError, "immutable"):
5810-
tp.foo = 1
5810+
support.check_immutable_type(self, tp)
58115811

58125812
def test_c_disallow_instantiation(self):
58135813
ContextManager = type(C.localcontext())

Lib/test/test_itertools.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,8 +1541,7 @@ def test_immutable_types(self):
15411541
)
15421542
for tp in dataset:
15431543
with self.subTest(tp=tp):
1544-
with self.assertRaisesRegex(TypeError, "immutable"):
1545-
tp.foobar = 1
1544+
support.check_immutable_type(self, tp)
15461545

15471546

15481547
class TestExamples(unittest.TestCase):

Lib/test/test_shutil.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from test import support
3333
from test.support import os_helper, socket_helper
3434
from test.support.os_helper import TESTFN, FakePath
35+
from test.support.import_helper import ensure_lazy_imports
3536

3637
TESTFN2 = TESTFN + "2"
3738
TESTFN_SRC = TESTFN + "_SRC"
@@ -2362,6 +2363,14 @@ def _boo(filename, extract_dir, extra):
23622363
unregister_unpack_format('Boo2')
23632364
self.assertEqual(get_unpack_formats(), formats)
23642365

2366+
def test_compression_wrappers_not_imported_by_shutil(self):
2367+
# gh-154904: Importing shutil must not pull in the compression
2368+
# wrappers: they are only needed once an archive is actually created
2369+
# or extracted, and importing them measurably slows down every
2370+
# process that uses shutil.
2371+
ensure_lazy_imports("shutil",
2372+
{"bz2", "lzma", "compression", "compression.zstd"})
2373+
23652374

23662375
class TestMisc(BaseTest, unittest.TestCase):
23672376

Lib/test/test_sys.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def test_getwindowsversion(self):
425425
self.assertEqual(v[2], v.build)
426426
self.assertEqual(v[3], v.platform)
427427
self.assertEqual(v[4], v.service_pack)
428+
support.check_immutable_type(self, type(v))
428429

429430
# This is how platform.py calls it. Make sure tuple
430431
# still has 5 elements
@@ -690,6 +691,7 @@ def test_attributes(self):
690691
self.assertEqual(algo, 0)
691692
self.assertGreaterEqual(sys.hash_info.cutoff, 0)
692693
self.assertLess(sys.hash_info.cutoff, 8)
694+
support.check_immutable_type(self, type(sys.hash_info))
693695

694696
self.assertIsInstance(sys.maxsize, int)
695697
self.assertIsInstance(sys.maxunicode, int)
@@ -893,11 +895,13 @@ def assert_raise_on_new_sys_type(self, sys_attr):
893895
# sys.flags, sys.version_info, and sys.getwindowsversion.
894896
support.check_disallow_instantiation(self, type(sys_attr), sys_attr)
895897

896-
def test_sys_flags_no_instantiation(self):
898+
def test_sys_flags_type(self):
897899
self.assert_raise_on_new_sys_type(sys.flags)
900+
support.check_immutable_type(self, type(sys.flags))
898901

899-
def test_sys_version_info_no_instantiation(self):
902+
def test_sys_version_info_type(self):
900903
self.assert_raise_on_new_sys_type(sys.version_info)
904+
support.check_immutable_type(self, type(sys.version_info))
901905

902906
def test_sys_getwindowsversion_no_instantiation(self):
903907
# Skip if not being run on Windows.
@@ -1954,6 +1958,7 @@ def test_asyncgen_hooks(self):
19541958
cur = sys.get_asyncgen_hooks()
19551959
self.assertIsNone(cur.firstiter)
19561960
self.assertIsNone(cur.finalizer)
1961+
support.check_immutable_type(self, type(cur))
19571962

19581963
# gh-118473
19591964
with self.assertRaises(TypeError):
@@ -1997,6 +2002,7 @@ def write(self, s):
19972002
self.assertEqual(out, b"")
19982003
self.assertEqual(err, b"")
19992004

2005+
20002006
@test.support.support_remote_exec_only
20012007
@test.support.cpython_only
20022008
class TestRemoteExec(unittest.TestCase):

0 commit comments

Comments
 (0)