[issue22057] The doc say all globals are copied on eval(), but only __builtins__ is copied
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
New submission from Alon Mishne: 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 ---------- assignee: docs@python components: Documentation messages: 223837 nosy: amishne, docs@python priority: normal severity: normal status: open title: The doc say all globals are copied on eval(), but only __builtins__ is copied versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Raymond Hettinger added the comment: Thanks for noticing this. Do you want to propose a patch? ---------- assignee: docs@python -> rhettinger nosy: +rhettinger stage: -> needs patch versions: -Python 3.1, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Alon Mishne added the comment: Patch for 2.7.8. The patch is just changing "globals are" to "mapping of ‘__builtins__’ is", and subsequent paragraph reformatting. ---------- keywords: +patch Added file: http://bugs.python.org/file36128/evalglobals2.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Alon Mishne added the comment: 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. ---------- Added file: http://bugs.python.org/file36129/evalglobals3.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Antti Haapala added the comment: +1 for this patch, the current documentation states it very wrong. ---------- nosy: +ztane _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Raymond Hettinger added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Martin Panter added the comment: “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. ---------- nosy: +martin.panter stage: needs patch -> patch review versions: +Python 3.6, Python 3.7 -Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Change by Berker Peksag <berker.peksag@gmail.com>: ---------- pull_requests: +8290 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Berker Peksag <berker.peksag@gmail.com> added the comment: I like Martin's suggestion in msg282262 and I've just created PR 8812 to implement it. ---------- nosy: +berker.peksag type: -> behavior versions: +Python 3.8 -Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Berker Peksag <berker.peksag@gmail.com> added the comment: New changeset 225b05548027d55aafb11b65f6a4a2bef2f5196f by Berker Peksag in branch 'master': bpo-22057: Clarify eval() documentation (GH-8812) https://github.com/python/cpython/commit/225b05548027d55aafb11b65f6a4a2bef2f... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +8296 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +8297 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset 0e1e8dbb0b99ec78f4567382428fdd46e2244d40 by Miss Islington (bot) in branch '3.7': bpo-22057: Clarify eval() documentation (GH-8812) https://github.com/python/cpython/commit/0e1e8dbb0b99ec78f4567382428fdd46e22... ---------- nosy: +miss-islington _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset f19579b8f1fcd2dd8ffaf3e443b09930057c01d1 by Miss Islington (bot) in branch '3.6': bpo-22057: Clarify eval() documentation (GH-8812) https://github.com/python/cpython/commit/f19579b8f1fcd2dd8ffaf3e443b09930057... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue22057> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Berker Peksag <berker.peksag@gmail.com> added the comment: Thanks for the review, Martin, and thanks for the report, Alon! ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue22057> _______________________________________
participants (6)
-
Alon Mishne
-
Antti Haapala
-
Berker Peksag
-
Martin Panter
-
miss-islington
-
Raymond Hettinger