[Python-checkins] bpo-30533: Add docs for `inspect.getmembers_static` (#29874)

DinoV webhook-mailer at python.org
Wed Dec 1 14:23:51 EST 2021


https://github.com/python/cpython/commit/c2bb29ce9ae4adb6a8123285ad3585907cd4cc73
commit: c2bb29ce9ae4adb6a8123285ad3585907cd4cc73
branch: main
author: Weipeng Hong <hongweichen8888 at sina.com>
committer: DinoV <dinoviehland at gmail.com>
date: 2021-12-01T11:23:46-08:00
summary:

bpo-30533: Add docs for `inspect.getmembers_static` (#29874)

* Add docs for `inspect.getmembers_static`

* update

files:
M Doc/library/inspect.rst
M Doc/whatsnew/3.11.rst

diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index 1074f977184bb..711f510d7dcb0 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -275,6 +275,24 @@ attributes:
       listed in the metaclass' custom :meth:`__dir__`.
 
 
+.. function:: getmembers_static(object[, predicate])
+
+    Return all the members of an object in a list of ``(name, value)``
+    pairs sorted by name without triggering dynamic lookup via the descriptor
+    protocol, __getattr__ or __getattribute__. Optionally, only return members
+    that satisfy a given predicate.
+
+    .. note::
+
+        :func:`getmembers_static` may not be able to retrieve all members
+        that getmembers can fetch (like dynamically created attributes)
+        and may find members that getmembers can't (like descriptors
+        that raise AttributeError). It can also return descriptor objects
+        instead of instance members in some cases.
+
+    .. versionadded:: 3.11
+
+
 .. function:: getmodulename(path)
 
    Return the name of the module named by the file *path*, without including the
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index 6853c04143512..345b2df43f403 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -207,6 +207,13 @@ fractions
   (Contributed by Mark Dickinson in :issue:`44547`.)
 
 
+inspect
+-------
+* Add :func:`inspect.getmembers_static`: return all members without
+  triggering dynamic lookup via the descriptor protocol. (Contributed by
+  Weipeng Hong in :issue:`30533`.)
+
+
 math
 ----
 * Add :func:`math.exp2`: return 2 raised to the power of x.



More information about the Python-checkins mailing list