Skip to content

Commit c2bb29c

Browse files
authored
bpo-30533: Add docs for inspect.getmembers_static (#29874)
* Add docs for `inspect.getmembers_static` * update
1 parent ee94aa0 commit c2bb29c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Doc/library/inspect.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,24 @@ attributes:
275275
listed in the metaclass' custom :meth:`__dir__`.
276276

277277

278+
.. function:: getmembers_static(object[, predicate])
279+
280+
Return all the members of an object in a list of ``(name, value)``
281+
pairs sorted by name without triggering dynamic lookup via the descriptor
282+
protocol, __getattr__ or __getattribute__. Optionally, only return members
283+
that satisfy a given predicate.
284+
285+
.. note::
286+
287+
:func:`getmembers_static` may not be able to retrieve all members
288+
that getmembers can fetch (like dynamically created attributes)
289+
and may find members that getmembers can't (like descriptors
290+
that raise AttributeError). It can also return descriptor objects
291+
instead of instance members in some cases.
292+
293+
.. versionadded:: 3.11
294+
295+
278296
.. function:: getmodulename(path)
279297

280298
Return the name of the module named by the file *path*, without including the

Doc/whatsnew/3.11.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ fractions
207207
(Contributed by Mark Dickinson in :issue:`44547`.)
208208

209209

210+
inspect
211+
-------
212+
* Add :func:`inspect.getmembers_static`: return all members without
213+
triggering dynamic lookup via the descriptor protocol. (Contributed by
214+
Weipeng Hong in :issue:`30533`.)
215+
216+
210217
math
211218
----
212219
* Add :func:`math.exp2`: return 2 raised to the power of x.

0 commit comments

Comments
 (0)