Title: __import__() change between 3.2 and 3.3
Type: Stage:
Components: Documentation, Interpreter Core Versions: Python 3.2, Python 3.3
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Arfrever, Ronan.Lamy, brett.cannon, docs@python, eric.snow, loewis, ncoghlan, python-dev
Priority: normal Keywords:

Created on 2012-07-29 02:55 by Ronan.Lamy, last changed 2012-08-06 00:50 by brett.cannon. This issue is now closed.

Messages (8)
msg166706 - (view) Author: Ronan Lamy (Ronan.Lamy) * Date: 2012-07-29 02:55
I noticed a change in the behaviour of __import__() between 3.2 and 3.3. It looks like in 3.2 __import__() does a Py2-style combo relative/absolute import. Here's a minimal test case:

$ ls foo  __pycache__
$ cat foo/
__import__('bar', globals(), locals())
$ python3.3 -c "import foo"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "./foo/", line 1, in <module>
    __import__('bar', globals(), locals())
ImportError: No module named 'bar'
$ python3.2 -c "import foo"

I believe that 3.3 is correct and that 3.2 is wrong but can't be changed now, so I suppose that 3.2 should just document the actual behaviour of __import__() and 3.3 should document the change. 

(The context is that I encountered issue 15434. This looks related, but I'm not sure it is.)
msg166707 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-07-29 03:31
See issue14592 (particularly msg158466).
msg166708 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-07-29 03:34
The specific bug is that, in 3.2, the claimed default (level=0) is not accurate: the default is actually (level=-1), as it was in 2.x. The import statement passes level=0 explicitly (as it does in 2.x when "from __future__ import absolute_import" is in effect).

The docstring in 3.2 is accurate, the prose documentation is incorrect.

In 3.3, the docstring is currently wrong, but the prose documentation is correct. However, it should have a "versionchanged: 3.3" not added, indicating that the default import level has finally been brought into compliance with the documentation.
msg166710 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-07-29 03:47
s/not added/note added/
msg166738 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-07-29 09:58
So should 3.2 be changed to adjust the default value to match the documentation?
msg166839 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-07-30 00:13
On Jul 29, 2012 5:58 AM, "Martin v. Löwis" <> wrote:
> Martin v. Löwis added the comment:
> So should 3.2 be changed to adjust the default value to match the

It is probably safe to do so.


> ----------
> nosy: +loewis
> _______________________________________
> Python tracker <>
> <>
> _______________________________________
msg167526 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-08-06 00:35
I just realized my reply was unclear; I meant changing Doc/library/functions.rst, not the code.

And 3.3 already has a versionchanged note about no longer accepting negative indexes, but I will update it to mention the new default as well explicitly.
msg167527 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-08-06 00:50
New changeset 3fe01f7520e2 by Brett Cannon in branch '3.2':
Issue #15482: Properly document the default 'level' parameter for

New changeset 05bec2e78a5c by Brett Cannon in branch 'default':
Issue #15482: Merge 78449:3fe01f7520e2 with a minor clarification.
Date User Action Args
2012-08-06 00:50:38brett.cannonsetstatus: open -> closed
resolution: fixed
2012-08-06 00:50:13python-devsetnosy: + python-dev
messages: + msg167527
2012-08-06 00:35:32brett.cannonsetmessages: + msg167526
2012-07-30 00:13:07brett.cannonsetmessages: + msg166839
2012-07-29 11:44:57Arfreversetnosy: + Arfrever
2012-07-29 09:58:43loewissetnosy: + loewis
messages: + msg166738
2012-07-29 03:47:00ncoghlansetmessages: + msg166710
2012-07-29 03:35:00ncoghlansetmessages: + msg166708
2012-07-29 03:31:09eric.snowsetnosy: + eric.snow
messages: + msg166707
2012-07-29 02:55:10Ronan.Lamycreate