Issue 14628: Clarify import statement documentation regarding what gets bound (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/58833

classification

Title: Clarify import statement documentation regarding what gets bound
Type: Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: Arfrever, benjamin.peterson, brett.cannon, docs@python, eric.snow, python-dev
Priority: normal Keywords:

Created on 2012-04-20 04:31 by eric.snow, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg158793 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-04-20 04:31
(see #14609 and #14582) http://docs.python.org/dev/reference/simple_stmts.html#the-import-statement The specification for the import statement says the following: "The first form of import statement binds the module name in the local namespace to the module object". This is not the case and has not been the case perhaps ever. Instead of getting bound to the module (returned by loader.load_module() during import), the name is bound to the value at sys.modules[module_name]. Normally two approaches yield the same result. However, if during import the sys.modules value for the module is assigned to something else, the behavior deviates from the specfication. See #14609 for an example. Considering the backwards-compatibility issues, the language reference should be updated to reflect the actual behavior.
msg158833 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-04-20 15:13
So I think the sentence is saying exactly what is going on, but you want clarification that the module object is originating from sys.modules specifically. So you could change the sentence to "The first form of import statement binds the module name in the local namespace to the module object as found in sys.modules."
msg158841 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-04-20 15:27
Sounds mostly right. sys.modules[name] won't necessarily contain a module object, as Benjamin brought up in .
msg158843 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-04-20 15:34
OK, so you say "to the object found in sys.modules."
msg158879 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-04-20 19:58
New changeset 150bd84e737e by Brett Cannon in branch 'default': Issue #14628: Document the fact that import always returns the module http://hg.python.org/cpython/rev/150bd84e737e
History
Date User Action Args
2022-04-11 14:57:29 admin set github: 58833
2012-04-20 19:58:32 brett.cannon set status: open -> closedassignee: docs@python -> brett.cannonresolution: fixedstage: resolved
2012-04-20 19:58:04 python-dev set nosy: + python-devmessages: +
2012-04-20 15:34:07 brett.cannon set messages: +
2012-04-20 15:27:57 eric.snow set messages: +
2012-04-20 15:13:51 brett.cannon set messages: +
2012-04-20 06:14:51 Arfrever set nosy: + Arfrever
2012-04-20 04:31:07 eric.snow create