This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: missing feature in inspect module: getmembers_static
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, carljm, corona10, dino.viehland, hongweipeng, itamaro, kernc, lisroach, xtreak
Priority: normal Keywords: patch

Created on 2017-05-31 22:52 by carljm, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 20911 merged hongweipeng, 2020-06-16 10:09
PR 29874 merged hongweipeng, 2021-12-01 08:56
Messages (7)
msg294876 - (view) Author: Carl Meyer (carljm) * Date: 2017-05-31 22:52
The inspect module contains a getattr_static() function, for accessing an arbitrary attribute on a Python object without risking descriptor or __getattr__ code execution. This is useful for introspection tools that don't want to trigger any side effects.

The inspect module also contains a getmembers() function, which returns a mapping of names to values for all the object's members. This function could also be very useful to introspection tools, except that internally it uses normal getattr, thus reintroduces the risk of arbitrary code execution.

It would be useful to have an equivalent to getmembers() that is descriptor-safe. This could be done either by introducing a new getmembers_static(), or possibly by adding a `getattr` optional keyword argument to getmembers, that would take a getattr-equivalent callable to use in fetching attributes from the object. (The latter option might render some internal assumptions of getmembers() incorrect, needs experimentation.)
msg295029 - (view) Author: Lisa Roach (lisroach) * (Python committer) Date: 2017-06-02 15:58
+1 to a new getmembers_static(), I don't see why this couldn't be implemented.
msg329255 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-11-04 20:26
+1 from me too. issue35108 could help from this implementation where properties execute code that might cause runtime exception. Initially I tried using getattr_static inside getmembers at msg329254 but I think a separate function or an option to use getattr_static only in getmembers is more clean.

Bumping the version to 3.8.

Thanks!
msg406072 - (view) Author: Itamar Ostricher (itamaro) * Date: 2021-11-10 04:41
interested in this too - came here to see if I can implement, but found that a patch is already available (GH-20911), and applies cleanly on latest main branch (see my PR comments)

would be great if it gets merged!
msg407393 - (view) Author: Dino Viehland (dino.viehland) * (Python committer) Date: 2021-11-30 18:23
New changeset af8c8caaf5e07c02202d736a31f6a2f7e27819b8 by Weipeng Hong in branch 'main':
bpo-30533:Add function inspect.getmembers_static that does not call properties or dynamic properties. (#20911)
https://github.com/python/cpython/commit/af8c8caaf5e07c02202d736a31f6a2f7e27819b8
msg407423 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-12-01 02:28
Please update the documentation also.

see: https://docs.python.org/3.11/library/inspect.html?highlight=inspect#inspect.getmembers
msg407483 - (view) Author: Dino Viehland (dino.viehland) * (Python committer) Date: 2021-12-01 19:23
New changeset c2bb29ce9ae4adb6a8123285ad3585907cd4cc73 by Weipeng Hong in branch 'main':
bpo-30533: Add docs for `inspect.getmembers_static` (#29874)
https://github.com/python/cpython/commit/c2bb29ce9ae4adb6a8123285ad3585907cd4cc73
History
Date User Action Args
2022-04-11 14:58:47adminsetgithub: 74718
2021-12-01 19:24:09dino.viehlandsetstatus: open -> closed
stage: patch review -> resolved
2021-12-01 19:23:50dino.viehlandsetmessages: + msg407483
2021-12-01 08:56:24hongweipengsetstage: resolved -> patch review
pull_requests: + pull_request28100
2021-12-01 02:28:10corona10setstatus: closed -> open
nosy: + corona10
messages: + msg407423

2021-11-30 22:53:17dino.viehlandsetstatus: open -> closed
stage: patch review -> resolved
versions: + Python 3.11, - Python 3.9
2021-11-30 18:23:22dino.viehlandsetnosy: + dino.viehland
messages: + msg407393
2021-11-10 04:41:25itamarosetnosy: + itamaro
messages: + msg406072
2020-06-16 10:09:41hongweipengsetkeywords: + patch
nosy: + hongweipeng

pull_requests: + pull_request20093
stage: patch review
2020-06-09 23:28:37lys.nikolaousetnosy: - lys.nikolaou
2020-06-09 23:27:00kerncsetnosy: + kernc
2019-10-29 10:14:49BTaskayasetnosy: + BTaskaya

versions: + Python 3.9, - Python 3.8
2018-11-05 23:17:53lys.nikolaousetnosy: + lys.nikolaou
2018-11-04 20:26:54xtreaksetnosy: + xtreak

messages: + msg329255
versions: + Python 3.8, - Python 3.7
2017-06-02 15:58:43lisroachsetnosy: + lisroach
messages: + msg295029
2017-05-31 22:52:48carljmcreate