[New-bugs-announce] [issue15598] relative import unexpectedly binds name

Antony Lee report at bugs.python.org
Thu Aug 9 02:18:08 CEST 2012


New submission from Antony Lee:

The language reference is clear:
"The from form does not bind the module name" (Section 6.12)

However, consider the following example:

* package/__init__.py:
foo = "FOO"
from .foo import bar
print(foo)
os = "OS"
from os import path
print(os)

* package/foo.py:
foo = 42

Now "import package" results in printing:
<module 'pypackage.foo' from 'pypackage/foo.py'>
OS

i.e., the relative "from ... import" has not only bound "bar", but also "foo", which seems to contradict the documentation.
(I get the same behaviour using 3.2.3 as well as 2.7.3.)

----------
messages: 167742
nosy: Antony.Lee
priority: normal
severity: normal
status: open
title: relative import unexpectedly binds name
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15598>
_______________________________________


More information about the New-bugs-announce mailing list