File tree Expand file tree Collapse file tree 1 file changed +20
-7
lines changed
Expand file tree Collapse file tree 1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -1259,19 +1259,32 @@ def test__Py_DECLARE_STR_is_interned(self):
12591259 with self .subTest (global_string = global_string ):
12601260 self .assertIsInterned (eval (f"'{ global_string } '" ))
12611261
1262+ noninternable_by_default = textwrap .dedent ('''
1263+ not-internable
1264+ not.internable
1265+ не_интернируемый
1266+ str with spaces
1267+ ''' + '\U00100000 ' )
1268+
12621269 @cpython_only
12631270 @unittest .skipIf (Py_GIL_DISABLED , "free-threaded build interns all string constants" )
12641271 def test_non_internable_strings_not_interned (self ):
1265- noninternable_strings = (
1266- "not-internable" ,
1267- "not.internable" ,
1268- "не_интернируемый" ,
1269- "" ,
1270- )
1271- for noninternable in noninternable_strings :
1272+ for noninternable in self .noninternable_by_default .strip ().splitlines ():
12721273 with self .subTest (noninternable = noninternable ):
12731274 self .assertIsNotInterned (eval (f"'{ noninternable } '" ))
12741275
1276+ @cpython_only
1277+ @unittest .skipIf (Py_GIL_DISABLED , "free-threaded build interns all string constants" )
1278+ def test_explicitly_interned_strings (self ):
1279+ for noninternable in self .noninternable_by_default .strip ().splitlines ():
1280+ self .assertIsNotInterned (noninternable )
1281+ sys .intern (noninternable )
1282+ with self .subTest (noninternable = noninternable ):
1283+ self .assertIsInterned (noninternable )
1284+ interned_from_code = eval (f"'{ noninternable } '" )
1285+ self .assertIsInterned (interned_from_code )
1286+ self .assertIs (noninternable , interned_from_code )
1287+
12751288class CodeWeakRefTest (unittest .TestCase ):
12761289
12771290 def test_basic (self ):
You can’t perform that action at this time.
0 commit comments