Skip to content

Commit 249b7d5

Browse files
ZackerySpytzencukou
authored andcommitted
bpo-20602: Do not clear sys.flags and sys.float_info during shutdown (GH-8096)
There is no need to clear these immutable objects during shutdown.
1 parent c145f3b commit 249b7d5

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Lib/test/test_sys.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,22 @@ def __del__(self):
822822
rc, stdout, stderr = assert_python_ok('-c', code)
823823
self.assertEqual(stdout.rstrip(), b'True')
824824

825+
@test.support.requires_type_collecting
826+
def test_issue20602(self):
827+
# sys.flags and sys.float_info were wiped during shutdown.
828+
code = """if 1:
829+
import sys
830+
class A:
831+
def __del__(self, sys=sys):
832+
print(sys.flags)
833+
print(sys.float_info)
834+
a = A()
835+
"""
836+
rc, out, err = assert_python_ok('-c', code)
837+
out = out.splitlines()
838+
self.assertIn(b'sys.flags', out[0])
839+
self.assertIn(b'sys.float_info', out[1])
840+
825841
@unittest.skipUnless(hasattr(sys, 'getandroidapilevel'),
826842
'need sys.getandroidapilevel()')
827843
def test_getandroidapilevel(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Do not clear :data:`sys.flags` and :data:`sys.float_info` during shutdown.
2+
Patch by Zackery Spytz.

Python/import.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,6 @@ static const char * const sys_deletes[] = {
383383
"last_type", "last_value", "last_traceback",
384384
"path_hooks", "path_importer_cache", "meta_path",
385385
"__interactivehook__",
386-
/* misc stuff */
387-
"flags", "float_info",
388386
NULL
389387
};
390388

0 commit comments

Comments
 (0)