]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-30533: Add docs for `inspect.getmembers_static` (#29874)
authorWeipeng Hong <hongweichen8888@sina.com>
Wed, 1 Dec 2021 19:23:46 +0000 (03:23 +0800)
committerGitHub <noreply@github.com>
Wed, 1 Dec 2021 19:23:46 +0000 (11:23 -0800)
* Add docs for `inspect.getmembers_static`

* update

Doc/library/inspect.rst
Doc/whatsnew/3.11.rst

index 1074f977184bb51c97e059b22bd76d3f56c2063e..711f510d7dcb03ef94874d13bd8ce6950fd73dad 100644 (file)
@@ -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
index 6853c04143512ccc0ab8a10709dd8bc0b78471be..345b2df43f40315ec3c952e64bae98010b521aa3 100644 (file)
@@ -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.