Issue 22057: The doc say all globals are copied on eval(), but only builtins is copied (original) (raw)

Created on 2014-07-24 13:59 by amishne, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
evalglobals2.patch amishne,2014-07-27 09:55 review
evalglobals3.patch amishne,2014-07-27 09:57 review
Pull Requests
URL Status Linked Edit
PR 8812 merged berker.peksag,2018-08-18 22:18
PR 8818 merged miss-islington,2018-08-19 10:25
PR 8819 merged miss-islington,2018-08-19 10:25
Messages (12)
msg223837 - (view) Author: Alon Mishne (amishne) * Date: 2014-07-24 13:59
According to the documentation of eval(): > If the globals dictionary is present and lacks '__builtins__', the current globals are copied into globals before expression is parsed. However in practice only the __builtins__ items are copied, see: http://hg.python.org/cpython/file/2.7/Python/bltinmodule.c#l655 See http://stackoverflow.com/q/24934908/242762
msg223971 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-07-25 17:08
Thanks for noticing this. Do you want to propose a patch?
msg224112 - (view) Author: Alon Mishne (amishne) * Date: 2014-07-27 09:55
Patch for 2.7.8. The patch is just changing "globals are" to "mapping of ‘__builtins__’ is", and subsequent paragraph reformatting.
msg224113 - (view) Author: Alon Mishne (amishne) * Date: 2014-07-27 09:57
Patch for 3.5.x The patch is just changing "globals are" to "mapping of ‘__builtins__’ is", and subsequent paragraph reformatting. Nearly identical to 2.7.8 patch.
msg242083 - (view) Author: Antti Haapala (ztane) * Date: 2015-04-26 21:54
+1 for this patch, the current documentation states it very wrong.
msg242105 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-04-27 07:41
The patch looks good (though it would have been easier to check the diff if the text had not be reflowed). I will apply it when I get a chance. Or if anyone else wants to grab it, go ahead.
msg282262 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-03 02:32
“the current mapping of '__builtins__' is copied into *globals* ” That sounds like we insert each individual builtin name, i.e. globals.update(builtins_mapping). But my understanding is that it is the __builtins__ global variable that is affected: globals["__builtins__"] = builtins_mapping What about borrowing the wording from exec(): If the *globals* dictionary is present and lacks ‘__builtins__’, a reference to the current mapping of ‘__builtins__’ is inserted under that key . . . See also Issue 26363, which also covers this problem.
msg323736 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-08-18 22:19
I like Martin's suggestion in and I've just created PR 8812 to implement it.
msg323748 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-08-19 10:25
New changeset 225b05548027d55aafb11b65f6a4a2bef2f5196f by Berker Peksag in branch 'master': bpo-22057: Clarify eval() documentation (GH-8812) https://github.com/python/cpython/commit/225b05548027d55aafb11b65f6a4a2bef2f5196f
msg323749 - (view) Author: miss-islington (miss-islington) Date: 2018-08-19 10:29
New changeset 0e1e8dbb0b99ec78f4567382428fdd46e2244d40 by Miss Islington (bot) in branch '3.7': bpo-22057: Clarify eval() documentation (GH-8812) https://github.com/python/cpython/commit/0e1e8dbb0b99ec78f4567382428fdd46e2244d40
msg323751 - (view) Author: miss-islington (miss-islington) Date: 2018-08-19 10:32
New changeset f19579b8f1fcd2dd8ffaf3e443b09930057c01d1 by Miss Islington (bot) in branch '3.6': bpo-22057: Clarify eval() documentation (GH-8812) https://github.com/python/cpython/commit/f19579b8f1fcd2dd8ffaf3e443b09930057c01d1
msg323752 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-08-19 10:53
Thanks for the review, Martin, and thanks for the report, Alon!
History
Date User Action Args
2022-04-11 14:58:06 admin set github: 66255
2018-08-19 10:53:32 berker.peksag set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2018-08-19 10:32:15 miss-islington set messages: +
2018-08-19 10:29:53 miss-islington set nosy: + miss-islingtonmessages: +
2018-08-19 10:25:54 miss-islington set pull_requests: + <pull%5Frequest8297>
2018-08-19 10:25:45 miss-islington set pull_requests: + <pull%5Frequest8296>
2018-08-19 10:25:40 berker.peksag set messages: +
2018-08-19 00:07:47 berker.peksag link issue26363 superseder
2018-08-18 22:19:40 berker.peksag set versions: + Python 3.8, - Python 3.5nosy: + berker.peksagmessages: + type: behavior
2018-08-18 22🔞08 berker.peksag set pull_requests: + <pull%5Frequest8290>
2016-12-03 02:32:54 martin.panter set versions: + Python 3.6, Python 3.7, - Python 3.4nosy: + martin.pantermessages: + stage: needs patch -> patch review
2015-04-27 07:41:20 rhettinger set messages: +
2015-04-26 21:54:24 ztane set nosy: + ztanemessages: +
2014-07-27 09:57:43 amishne set files: + evalglobals3.patchmessages: +
2014-07-27 09:55:55 amishne set files: + evalglobals2.patchkeywords: + patchmessages: +
2014-07-25 17:08:55 rhettinger set versions: - Python 3.1, Python 3.2, Python 3.3nosy: + rhettingermessages: + assignee: docs@python -> rhettingerstage: needs patch
2014-07-24 13:59:49 amishne create