From 1f6eff32577d5564021da24be05418ee81e347f6 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Mon, 19 Oct 2026 11:41:02 -0700 Subject: [PATCH] gh-159730: Warn that gc.get_objects() can expose objects under construction --- Doc/library/gc.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/library/gc.rst b/Doc/library/gc.rst index 65533e7e57adc3..84edd0a5b56115 100644 --- a/Doc/library/gc.rst +++ b/Doc/library/gc.rst @@ -75,6 +75,12 @@ The :mod:`!gc` module provides the following functions: returned. If *generation* is not ``None``, return only the objects tracked by the collector that are in that generation. + .. warning:: + Care must be taken when using objects returned by :func:`get_objects` because + some of them could still be under construction and hence in a temporarily + invalid state. Avoid using :func:`get_objects` for any purpose other than + debugging. + .. versionchanged:: 3.8 New *generation* parameter.