Skip to content

Commit dfc7f82

Browse files
committed
pythongh-80527: Change support.requires_legacy_unicode_capi()
The decorator now requires to be called with parenthesis: @support.requires_legacy_unicode_capi() instead of: @support.requires_legacy_unicode_capi The implementation now only imports _testcapi when the decorator is called, so "import test.support" no longer imports the _testcapi extension.
1 parent b780882 commit dfc7f82

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

Lib/test/support/__init__.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
from .testresult import get_test_runner
2222

2323

24-
try:
25-
from _testcapi import unicode_legacy_string
26-
except ImportError:
27-
unicode_legacy_string = None
28-
2924
__all__ = [
3025
# globals
3126
"PIPE_MAX_SIZE", "verbose", "max_memuse", "use_resources", "failfast",
@@ -507,8 +502,14 @@ def has_no_debug_ranges():
507502
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
508503
return unittest.skipIf(has_no_debug_ranges(), reason)
509504

510-
requires_legacy_unicode_capi = unittest.skipUnless(unicode_legacy_string,
511-
'requires legacy Unicode C API')
505+
def requires_legacy_unicode_capi():
506+
try:
507+
from _testcapi import unicode_legacy_string
508+
except ImportError:
509+
unicode_legacy_string = None
510+
511+
return unittest.skipUnless(unicode_legacy_string,
512+
'requires legacy Unicode C API')
512513

513514
# Is not actually used in tests, but is kept for compatibility.
514515
is_jython = sys.platform.startswith('java')

Lib/test/test_capi/test_getargs.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ def test_et_hash(self):
10041004
buf = bytearray()
10051005
self.assertRaises(ValueError, getargs_et_hash, 'abc\xe9', 'latin1', buf)
10061006

1007-
@support.requires_legacy_unicode_capi
1007+
@support.requires_legacy_unicode_capi()
10081008
def test_u(self):
10091009
from _testcapi import getargs_u
10101010
with self.assertWarns(DeprecationWarning):
@@ -1020,7 +1020,7 @@ def test_u(self):
10201020
with self.assertWarns(DeprecationWarning):
10211021
self.assertRaises(TypeError, getargs_u, None)
10221022

1023-
@support.requires_legacy_unicode_capi
1023+
@support.requires_legacy_unicode_capi()
10241024
def test_u_hash(self):
10251025
from _testcapi import getargs_u_hash
10261026
with self.assertWarns(DeprecationWarning):
@@ -1036,7 +1036,7 @@ def test_u_hash(self):
10361036
with self.assertWarns(DeprecationWarning):
10371037
self.assertRaises(TypeError, getargs_u_hash, None)
10381038

1039-
@support.requires_legacy_unicode_capi
1039+
@support.requires_legacy_unicode_capi()
10401040
def test_Z(self):
10411041
from _testcapi import getargs_Z
10421042
with self.assertWarns(DeprecationWarning):
@@ -1052,7 +1052,7 @@ def test_Z(self):
10521052
with self.assertWarns(DeprecationWarning):
10531053
self.assertIsNone(getargs_Z(None))
10541054

1055-
@support.requires_legacy_unicode_capi
1055+
@support.requires_legacy_unicode_capi()
10561056
def test_Z_hash(self):
10571057
from _testcapi import getargs_Z_hash
10581058
with self.assertWarns(DeprecationWarning):

Lib/test/test_csv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def test_writerows_errors(self):
282282
self.assertRaises(OSError, writer.writerows, BadIterable())
283283

284284
@support.cpython_only
285-
@support.requires_legacy_unicode_capi
285+
@support.requires_legacy_unicode_capi()
286286
@warnings_helper.ignore_warnings(category=DeprecationWarning)
287287
def test_writerows_legacy_strings(self):
288288
import _testcapi

Lib/test/test_decimal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def test_explicit_from_string(self):
588588
self.assertRaises(InvalidOperation, Decimal, "1_2_\u00003")
589589

590590
@cpython_only
591-
@requires_legacy_unicode_capi
591+
@requires_legacy_unicode_capi()
592592
@warnings_helper.ignore_warnings(category=DeprecationWarning)
593593
def test_from_legacy_strings(self):
594594
import _testcapi
@@ -2920,7 +2920,7 @@ def test_none_args(self):
29202920
Overflow])
29212921

29222922
@cpython_only
2923-
@requires_legacy_unicode_capi
2923+
@requires_legacy_unicode_capi()
29242924
@warnings_helper.ignore_warnings(category=DeprecationWarning)
29252925
def test_from_legacy_strings(self):
29262926
import _testcapi

Lib/test/test_str.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def test_isidentifier(self):
813813
self.assertFalse("0".isidentifier())
814814

815815
@support.cpython_only
816-
@support.requires_legacy_unicode_capi
816+
@support.requires_legacy_unicode_capi()
817817
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
818818
def test_isidentifier_legacy(self):
819819
u = '𝖀𝖓𝖎𝖈𝖔𝖉𝖊'
@@ -2490,7 +2490,7 @@ def test_getnewargs(self):
24902490
self.assertEqual(len(args), 1)
24912491

24922492
@support.cpython_only
2493-
@support.requires_legacy_unicode_capi
2493+
@support.requires_legacy_unicode_capi()
24942494
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
24952495
def test_resize(self):
24962496
for length in range(1, 100, 7):

0 commit comments

Comments
 (0)