msg204052 - (view) |
Author: Zahari Dim (Zahari.Dim) |
Date: 2013-11-23 16:51 |
The globals() notification states: Return a dictionary representing the current global symbol table.[...] This doc and the fact that globals() is called as a function made me think that globals() returns a copy of the global namespace dict, rather than an object that could be used to actually modify the namespace. I don't find obvious the meaning of "representing" in this context. This of course led to a very nasty and sneaky bug in my code. The docs of locals() don't seem clear to me either, thought at least it seems to imply that it is actually modifying the namespace. |
|
|
msg204055 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2013-11-23 17:06 |
We've tried improving the locals docs several times. Modifying it is not "safe", in the sense that what happens when you do is not defined by the language. Which locals docs were you looking at? I agree that 'representing' is not as clear as would be optimal in the globals description. Again, which bit of the docs are you looking at? |
|
|
msg204128 - (view) |
Author: Zahari Dim (Zahari.Dim) |
Date: 2013-11-23 23:37 |
I am looking at the docs of the built-in functions: http://docs.python.org/2/library/functions.html |
|
|
msg204769 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2013-11-30 03:25 |
In my opinion, vague ideas like this one should go to python-ideas first. I agree with David that globals() and locals() are separate issues. Since there have been and perhaps still are locals() doc issues, I will take this one to be about 'globals()'. A 'symbol table' is a mapping between 'symbols' and 'values'. I presume such were originally implemented as a concrete list of pairs, but the term is now is an abstraction. In the Python context, I think 'namespace' would be a better word, but I would not make the change without getting other opinions, such as on python-ideas. The [...] that you omitted says "This is always the dictionary of the current module (...)." I cannot interpret 'is' to mean a copy. So I think "[concrete] dictionary represents [abstract] symbol table [namespace]" is fine. |
|
|
msg204777 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2013-11-30 05:31 |
How about swapping the two sentences for globals() then: “Returns the dictionary of the module . . . This represents the symbol table . . .” I thought the current locals() entry is fairly clear. It actually says _not_ to modify the dictionary! |
|
|
msg232796 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2014-12-17 02:51 |
Here is a patch with my suggestion. It also now refers to _the_ dictionary rather than just _a_ dictionary, and drops the word “current”, so that it does not sound like saving a snapshot. |
|
|
msg243430 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2015-05-17 22:13 |
My succinct version: Return the dictionary implementing the current module namespace. For code within functions, this is set when the function is defined and remains the same regardless of where a function is called. |
|
|
msg243547 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2015-05-18 22:46 |
Terry’s “dictionary implementing the namespace” version would work for me. |
|
|
msg408277 - (view) |
Author: Łukasz Langa (lukasz.langa) *  |
Date: 2021-12-11 00:04 |
New changeset 4fe5585240f64c3d14eb635ff82b163f92074b3a by 180909 in branch 'main': bpo-19737: Improved the documentation for globals (GH-29823) https://github.com/python/cpython/commit/4fe5585240f64c3d14eb635ff82b163f92074b3a |
|
|
msg408281 - (view) |
Author: Łukasz Langa (lukasz.langa) *  |
Date: 2021-12-11 00:32 |
New changeset 1f7000808e8385e2a29ffd0ef6aac9a6139d3d92 by Miss Islington (bot) in branch '3.10': bpo-19737: Improved the documentation for globals (GH-29823) (GH-30041) https://github.com/python/cpython/commit/1f7000808e8385e2a29ffd0ef6aac9a6139d3d92 |
|
|
msg408282 - (view) |
Author: Łukasz Langa (lukasz.langa) *  |
Date: 2021-12-11 00:32 |
New changeset 9299e3a39c3b1dd7d5db0d88080249c2dab3070f by Miss Islington (bot) in branch '3.9': bpo-19737: Improved the documentation for globals (GH-29823) (GH-30042) https://github.com/python/cpython/commit/9299e3a39c3b1dd7d5db0d88080249c2dab3070f |
|
|
msg408283 - (view) |
Author: Łukasz Langa (lukasz.langa) *  |
Date: 2021-12-11 00:33 |
Thanks! ✨ 🍰 ✨ |
|
|