From 00b157dfc5dfb790ba63df5ee880cb9d5ba86b99 Mon Sep 17 00:00:00 2001 From: Sreehari Annam Date: Sun, 12 Jul 2026 10:04:29 -0400 Subject: [PATCH 1/2] gh-62172: Document classify_class_attrs(), getabsfile(), and indentsize() in inspect --- Doc/library/inspect.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index a0f7379b12a8a62..a49ea503e6367f6 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -736,6 +736,15 @@ Retrieving source code class, or function. +.. function:: getabsfile(object) + + Return an absolute path to the (text or binary) file in which an object + was defined, normalized for the current platform using + :func:`os.path.normcase`. This uses :func:`getsourcefile` and falls back + to :func:`getfile` if no source file can be found. The idea is for each + object to have a unique origin. + + .. function:: getmodule(object) Try to guess which module an object was defined in. Return ``None`` @@ -791,6 +800,12 @@ Retrieving source code expanded to spaces. +.. function:: indentsize(line) + + Return the indentation size, in number of spaces, at the start of a line + of text, expanding tabs using :meth:`str.expandtabs`. + + .. _inspect-signature-object: Introspecting callables with the Signature object @@ -1220,6 +1235,20 @@ function. Classes and functions --------------------- +.. function:: classify_class_attrs(cls) + + Return a list of ``Attribute(name, kind, defining_class, object)`` named + tuples for each attribute reported by ``dir(cls)``. *kind* is one of + ``'class method'``, ``'static method'``, ``'property'``, ``'method'`` or + ``'data'``, and *defining_class* is the class in *cls*'s :term:`MRO` (or + its metaclass's MRO) that defines the attribute. *object* is the + attribute value, retrieved with :func:`getattr` where possible, falling + back to a lookup in the defining class's ``__dict__``. + + This is used internally by :mod:`pydoc` to build the class documentation + shown by :func:`help`. + + .. function:: getclasstree(classes, unique=False) Arrange the given list of classes into a hierarchy of nested lists. Where a From c4e2a2675913157762252ed05149c3f253b633b0 Mon Sep 17 00:00:00 2001 From: Sreehari Annam Date: Sun, 12 Jul 2026 11:18:46 -0400 Subject: [PATCH 2/2] Address review feedback: simplify getabsfile wording, link named tuple term --- Doc/library/inspect.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index a49ea503e6367f6..eefc93ea90192fa 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -738,11 +738,10 @@ Retrieving source code .. function:: getabsfile(object) - Return an absolute path to the (text or binary) file in which an object - was defined, normalized for the current platform using - :func:`os.path.normcase`. This uses :func:`getsourcefile` and falls back - to :func:`getfile` if no source file can be found. The idea is for each - object to have a unique origin. + Return an absolute, normalized path to the (text or binary) file in + which an object was defined. This uses :func:`getsourcefile` and falls + back to :func:`getfile` if no source file can be found. The idea is for + each object to have a unique origin. .. function:: getmodule(object) @@ -1237,8 +1236,9 @@ Classes and functions .. function:: classify_class_attrs(cls) - Return a list of ``Attribute(name, kind, defining_class, object)`` named - tuples for each attribute reported by ``dir(cls)``. *kind* is one of + Return a list of :term:`named tuples ` + ``Attribute(name, kind, defining_class, object)`` for each attribute + reported by ``dir(cls)``. *kind* is one of ``'class method'``, ``'static method'``, ``'property'``, ``'method'`` or ``'data'``, and *defining_class* is the class in *cls*'s :term:`MRO` (or its metaclass's MRO) that defines the attribute. *object* is the