From 1c56bc611f407a08227600b47222a93118329cf0 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 27 Nov 2026 23:43:41 +0200 Subject: [PATCH] gh-64352: Fix outdated statement about module globals at shutdown in weakref docs Module globals can still be replaced by None during interpreter shutdown for modules that are still alive late in the shutdown. --- Doc/library/weakref.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst index 94a55240b66598..a541059c88afc3 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -614,11 +614,14 @@ follows:: self.remove() Starting with Python 3.4, :meth:`~object.__del__` methods no longer prevent -reference cycles from being garbage collected, and module globals are -no longer forced to :const:`None` during :term:`interpreter shutdown`. -So this code should work without any issues on CPython. - -However, handling of :meth:`~object.__del__` methods is notoriously implementation +reference cycles from being garbage collected, +and most modules are garbage collected during :term:`interpreter shutdown` +instead of having their globals forced to :const:`None`. +But globals of modules that are still alive late in the shutdown +can still be replaced by :const:`None`, +so a :meth:`!__del__` method called at that time may fail. + +Moreover, handling of :meth:`~object.__del__` methods is notoriously implementation specific, since it depends on internal details of the interpreter's garbage collector implementation.