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: Status of __builtins__ is not totally clear
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Malcolm Smith, Mariatta, NaomiCeder, brett.cannon, docs@python, terry.reedy
Priority: normal Keywords:

Created on 2017-05-15 16:20 by Malcolm Smith, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1725 merged NaomiCeder, 2017-05-22 20:40
PR 1727 merged Mariatta, 2017-05-22 21:17
Messages (7)
msg293722 - (view) Author: Malcolm Smith (Malcolm Smith) Date: 2017-05-15 16:20
https://docs.python.org/3.6/reference/executionmodel.html#builtins-and-restricted-execution describes the various things you can do with __builtins__, but then says "Users should not touch __builtins__; it is strictly an implementation detail." If this is so, the entire section should be marked "CPython implementation detail", not just that last paragraph.

Elsewhere, https://docs.python.org/3.6/reference/import.html#replacing-the-standard-import-system suggests that the __import__ function could be replaced "at the module level to only alter the behaviour of import statements within that module". Is there any way of doing this other than manipulating the module's __builtins__? If not, this is encouraging the programmer to rely on a CPython implementation detail without marking it as such.
msg293773 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2017-05-16 16:28
You're correct that both are CPython implementation details and could be more clearly marked as such.

(In case anyone is curious, the code to look up __import__() can be found at https://github.com/python/cpython/blob/c7ac7280c321b3c1679fe5f657a6be0f86adf173/Python/ceval.c#L4991 .)
msg293972 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-05-19 20:06
Moving "CPython implementation detail: " up a paragraph should be trivial.  Resolving the conflict between " __builtins__ can be set to a user-created dictionary to create a weak form of restricted execution." and "Users should not touch __builtins__;" seems less so.  I suspect the the latter was added well after the former, and that the former should have been deleted at that time.
msg294181 - (view) Author: Naomi Ceder (NaomiCeder) * Date: 2017-05-22 20:41
Created a PR on this... it seems that making the Implementation Detail warning come first and deleting the limited execution sentence achieves what's needed here.
msg294183 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-05-22 21:09
New changeset 43c8a9e39bb2d4f25ed7ae17a55f34e375d1868b by Mariatta (Naomi Ceder) in branch 'master':
bpo-30372: Clarify that '__builtins__' is a CPython Implementation detail (GH-1725)
https://github.com/python/cpython/commit/43c8a9e39bb2d4f25ed7ae17a55f34e375d1868b
msg294188 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-05-22 21:36
New changeset 3d3b189f8ef321ccfb144a46d50892939d6004aa by Mariatta in branch '3.6':
[3.6] bpo-30372: Clarify that '__builtins__' is a CPython Implementation detail (GH-1725) (GH-1727)
https://github.com/python/cpython/commit/3d3b189f8ef321ccfb144a46d50892939d6004aa
msg294189 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-05-22 21:37
PR merged, and I backport it to 3.6

Thanks everyone :)
History
Date User Action Args
2022-04-11 14:58:46adminsetgithub: 74557
2017-05-22 21:37:09Mariattasetstatus: open -> closed
resolution: fixed
messages: + msg294189

stage: patch review -> resolved
2017-05-22 21:36:21Mariattasetmessages: + msg294188
2017-05-22 21:17:05Mariattasetpull_requests: + pull_request1817
2017-05-22 21:09:57Mariattasetnosy: + Mariatta
messages: + msg294183
2017-05-22 20:50:13Mariattasetstage: needs patch -> patch review
versions: + Python 3.7
2017-05-22 20:41:19NaomiCedersetnosy: + NaomiCeder
messages: + msg294181
2017-05-22 20:40:12NaomiCedersetpull_requests: + pull_request1813
2017-05-19 20:06:01terry.reedysetnosy: + terry.reedy
messages: + msg293972

type: behavior
stage: needs patch
2017-05-16 16:28:00brett.cannonsetnosy: + brett.cannon
messages: + msg293773
2017-05-15 16:20:38Malcolm Smithcreate