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):
72957295 """ )
72967296 script_helper .assert_python_ok ('-c' , script )
72977297
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-
73177298
73187299def load_tests (loader , standard_tests , pattern ):
73197300 standard_tests .addTest (ZoneInfoCompleteTest ())
Original file line number Diff line number Diff line change @@ -1517,6 +1517,29 @@ def test_ast_fini(self):
15171517 """ )
15181518 assert_python_ok ("-c" , code )
15191519
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+
15201543
15211544def setUpModule ():
15221545 global enabled , debug
You can’t perform that action at this time.
0 commit comments