Issue 32413: Document that locals() may return globals() (original) (raw)

Issue32413

Created on 2017-12-23 05:52 by steven.daprano, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5004 merged thatiparthy,2017-12-24 17:31
PR 12664 merged miss-islington,2019-04-02 17:59
Messages (5)
msg308947 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2017-12-23 05:52
The obvious documentation for locals() fails to mention that when called from the top level of a module (outside of a function or class body) it returns the same dict as globals(). https://docs.python.org/2/library/functions.html#locals
msg308949 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-12-23 08:12
FWIW, this isn't a quirk of how locals() works. Instead, it reflects the more interesting reality that at the top level, locals and globals *are* the same dictionary. Also, that is not the only occurrence -- if exec() is called with only one dictionary, that dict is used for both locals and globals.
msg309004 - (view) Author: Srinivas Reddy Thatiparthy(శ్రీనివాస్ రెడ్డి తాటిపర్తి) (thatiparthy) * Date: 2017-12-24 17:42
Done. exec(...)'s documentation covers raymond's comment.
msg309391 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-01-02 19:37
FWIW a few years ago I wrote a patch for Issue 17546 that documents three personalities of “locals”, including: * At the module level, the dictionary returned is the global symbol table, also returned by :func:`globals`.
msg339359 - (view) Author: miss-islington (miss-islington) Date: 2019-04-02 18:14
New changeset ef516d11c1a0f885dba0aba8cf5366502077cdd4 by Miss Islington (bot) in branch '3.7': bpo-32413: Add documentation that at the module level, locals(), globals() are the same dictionary (GH-5004) https://github.com/python/cpython/commit/ef516d11c1a0f885dba0aba8cf5366502077cdd4
History
Date User Action Args
2022-04-11 14:58:56 admin set github: 76594
2019-04-02 18:15:54 brett.cannon set status: open -> closedresolution: fixedstage: patch review -> resolved
2019-04-02 18:14:56 miss-islington set nosy: + miss-islingtonmessages: +
2019-04-02 17:59:08 miss-islington set pull_requests: + <pull%5Frequest12592>
2019-04-01 21:54:37 brett.cannon set nosy: + brett.cannon
2018-01-02 19:37:13 martin.panter set nosy: + martin.pantermessages: +
2017-12-24 17:42:42 thatiparthy set nosy: + thatiparthymessages: +
2017-12-24 17:31:13 thatiparthy set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest4893>
2017-12-23 08:12:02 rhettinger set messages: +
2017-12-23 08:09:45 rhettinger set nosy: + rhettinger
2017-12-23 05:52:42 steven.daprano create