]> granicus.if.org Git - python/commitdiff
bpo-20602: Do not clear sys.flags and sys.float_info during shutdown (GH-8096)
authorZackery Spytz <zspytz@gmail.com>
Thu, 30 May 2019 11:08:24 +0000 (05:08 -0600)
committerPetr Viktorin <pviktori@redhat.com>
Thu, 30 May 2019 11:08:24 +0000 (13:08 +0200)
There is no need to clear these immutable objects during shutdown.

Lib/test/test_sys.py
Misc/NEWS.d/next/Core and Builtins/2018-07-04-16-57-59.bpo-20602.sDLElw.rst [new file with mode: 0644]
Python/import.c

index c558d116e6fe9d65c2528bf3154c36442f21a174..49f2722d95140ee3fd23f7b3392195a4bce77b87 100644 (file)
@@ -822,6 +822,22 @@ class SysModuleTest(unittest.TestCase):
         rc, stdout, stderr = assert_python_ok('-c', code)
         self.assertEqual(stdout.rstrip(), b'True')
 
+    @test.support.requires_type_collecting
+    def test_issue20602(self):
+        # sys.flags and sys.float_info were wiped during shutdown.
+        code = """if 1:
+            import sys
+            class A:
+                def __del__(self, sys=sys):
+                    print(sys.flags)
+                    print(sys.float_info)
+            a = A()
+            """
+        rc, out, err = assert_python_ok('-c', code)
+        out = out.splitlines()
+        self.assertIn(b'sys.flags', out[0])
+        self.assertIn(b'sys.float_info', out[1])
+
     @unittest.skipUnless(hasattr(sys, 'getandroidapilevel'),
                          'need sys.getandroidapilevel()')
     def test_getandroidapilevel(self):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-07-04-16-57-59.bpo-20602.sDLElw.rst b/Misc/NEWS.d/next/Core and Builtins/2018-07-04-16-57-59.bpo-20602.sDLElw.rst
new file mode 100644 (file)
index 0000000..ab37a02
--- /dev/null
@@ -0,0 +1,2 @@
+Do not clear :data:`sys.flags` and :data:`sys.float_info` during shutdown.
+Patch by Zackery Spytz.
index 41a5c01cadf3ad528fd8cb94a50e6aaef152426f..ab7db6bc17f6b1225902999cbeb2489eb3faa334 100644 (file)
@@ -383,8 +383,6 @@ static const char * const sys_deletes[] = {
     "last_type", "last_value", "last_traceback",
     "path_hooks", "path_importer_cache", "meta_path",
     "__interactivehook__",
-    /* misc stuff */
-    "flags", "float_info",
     NULL
 };