File tree Expand file tree Collapse file tree 2 files changed +23
-19
lines changed Expand file tree Collapse file tree 2 files changed +23
-19
lines changed Original file line number Diff line number Diff line change @@ -7295,25 +7295,6 @@ def test_update_type_cache(self):
7295
7295
""" )
7296
7296
script_helper .assert_python_ok ('-c' , script )
7297
7297
7298
- def test_static_type_at_shutdown (self ):
7299
- # gh-132413
7300
- script = textwrap .dedent ("""
7301
- import _datetime
7302
- timedelta = _datetime.timedelta
7303
-
7304
- def gen():
7305
- try:
7306
- yield
7307
- finally:
7308
- # sys.modules is empty
7309
- _datetime.timedelta(days=1)
7310
- timedelta(days=1)
7311
-
7312
- it = gen()
7313
- next(it)
7314
- """ )
7315
- script_helper .assert_python_ok ('-c' , script )
7316
-
7317
7298
7318
7299
def load_tests (loader , standard_tests , pattern ):
7319
7300
standard_tests .addTest (ZoneInfoCompleteTest ())
Original file line number Diff line number Diff line change @@ -1517,6 +1517,29 @@ def test_ast_fini(self):
1517
1517
""" )
1518
1518
assert_python_ok ("-c" , code )
1519
1519
1520
+ def test_weakref_to_module_at_shutdown (self ):
1521
+ # gh-132413: Weakref gets cleared before modules are finalized
1522
+ code = textwrap .dedent ("""
1523
+ import os # any module other than sys
1524
+
1525
+ def gen():
1526
+ import weakref
1527
+ wr = weakref.ref(os)
1528
+ try:
1529
+ yield
1530
+ finally:
1531
+ print(
1532
+ os is not None,
1533
+ os is wr()
1534
+ )
1535
+
1536
+ it = gen()
1537
+ next(it)
1538
+ # quirk: Shutdown starts, then the finally block above follows
1539
+ """ )
1540
+ res = assert_python_ok ('-c' , code )
1541
+ self .assertEqual (res .out .rstrip (), b'True True' )
1542
+
1520
1543
1521
1544
def setUpModule ():
1522
1545
global enabled , debug
You can’t perform that action at this time.
0 commit comments