Skip to content

Commit 0eb6d87

Browse files
[3.12] pythongh-80527: Change support.requires_legacy_unicode_capi() (pythonGH-108438) (python#108446)
pythongh-80527: Change support.requires_legacy_unicode_capi() (pythonGH-108438) 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. (cherry picked from commit 995f4c4) Co-authored-by: Victor Stinner <[email protected]>
1 parent 2262190 commit 0eb6d87

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

Lib/test/support/__init__.py

Lines changed: 8 additions & 7 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def test_et_hash(self):
10211021
buf = bytearray()
10221022
self.assertRaises(ValueError, getargs_et_hash, 'abc\xe9', 'latin1', buf)
10231023

1024-
@support.requires_legacy_unicode_capi
1024+
@support.requires_legacy_unicode_capi()
10251025
def test_u(self):
10261026
from _testcapi import getargs_u
10271027
with self.assertWarns(DeprecationWarning):
@@ -1037,7 +1037,7 @@ def test_u(self):
10371037
with self.assertWarns(DeprecationWarning):
10381038
self.assertRaises(TypeError, getargs_u, None)
10391039

1040-
@support.requires_legacy_unicode_capi
1040+
@support.requires_legacy_unicode_capi()
10411041
def test_u_hash(self):
10421042
from _testcapi import getargs_u_hash
10431043
with self.assertWarns(DeprecationWarning):
@@ -1053,7 +1053,7 @@ def test_u_hash(self):
10531053
with self.assertWarns(DeprecationWarning):
10541054
self.assertRaises(TypeError, getargs_u_hash, None)
10551055

1056-
@support.requires_legacy_unicode_capi
1056+
@support.requires_legacy_unicode_capi()
10571057
def test_Z(self):
10581058
from _testcapi import getargs_Z
10591059
with self.assertWarns(DeprecationWarning):
@@ -1069,7 +1069,7 @@ def test_Z(self):
10691069
with self.assertWarns(DeprecationWarning):
10701070
self.assertIsNone(getargs_Z(None))
10711071

1072-
@support.requires_legacy_unicode_capi
1072+
@support.requires_legacy_unicode_capi()
10731073
def test_Z_hash(self):
10741074
from _testcapi import getargs_Z_hash
10751075
with self.assertWarns(DeprecationWarning):

Lib/test/test_csv.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def test_explicit_from_string(self):
587587
self.assertRaises(InvalidOperation, Decimal, "1_2_\u00003")
588588

589589
@cpython_only
590-
@requires_legacy_unicode_capi
590+
@requires_legacy_unicode_capi()
591591
@warnings_helper.ignore_warnings(category=DeprecationWarning)
592592
def test_from_legacy_strings(self):
593593
import _testcapi
@@ -2919,7 +2919,7 @@ def test_none_args(self):
29192919
Overflow])
29202920

29212921
@cpython_only
2922-
@requires_legacy_unicode_capi
2922+
@requires_legacy_unicode_capi()
29232923
@warnings_helper.ignore_warnings(category=DeprecationWarning)
29242924
def test_from_legacy_strings(self):
29252925
import _testcapi

Lib/test/test_unicode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ def test_isidentifier(self):
814814
self.assertFalse("0".isidentifier())
815815

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

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

0 commit comments

Comments
 (0)