bpo-39322: Add gc.is_finalized to check if an object has been finalised by the gc (GH-17989)
diff --git a/Doc/library/gc.rst b/Doc/library/gc.rst
index 13eda91..0c33c86 100644
--- a/Doc/library/gc.rst
+++ b/Doc/library/gc.rst
@@ -177,6 +177,27 @@
.. versionadded:: 3.1
+.. function:: is_finalized(obj)
+
+ Returns ``True`` if the given object has been finalized by the
+ garbage collector, ``False`` otherwise. ::
+
+ >>> x = None
+ >>> class Lazarus:
+ ... def __del__(self):
+ ... global x
+ ... x = self
+ ...
+ >>> lazarus = Lazarus()
+ >>> gc.is_finalized(lazarus)
+ False
+ >>> del lazarus
+ >>> gc.is_finalized(x)
+ True
+
+ .. versionadded:: 3.9
+
+
.. function:: freeze()
Freeze all the objects tracked by gc - move them to a permanent generation
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index 00409af..c949999 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -174,6 +174,10 @@
been executed), do not block the collection of all objects that are still
unreachable. (Contributed by Pablo Galindo and Tim Peters in :issue:`38379`.)
+Added a new function :func:`gc.is_finalized` to check if an object has been
+finalized by the garbage collector. (Contributed by Pablo Galindo in
+:issue:`39322`.)
+
imaplib
-------