[New-bugs-announce] [issue16570] Absolute imports fail to take full path into account?

Dirkjan Ochtman report at bugs.python.org
Wed Nov 28 15:46:11 CET 2012


New submission from Dirkjan Ochtman:

This seems confusing:

djc at enrai test $ ls -lR
.:
total 0
drwxr-xr-x 4 djc users 160 Nov 28 15:35 pkg

./pkg:
total 4
-rw-r--r-- 1 djc users  39 Nov 28 15:37 http.py
-rw-r--r-- 1 djc users   0 Nov 28 15:34 __init__.py
drwxr-xr-x 3 djc users 136 Nov 28 15:40 tests

./pkg/tests:
total 8
-rw-r--r-- 1 djc users  21 Nov 28 15:37 http.py
-rw-r--r-- 1 djc users  27 Nov 28 15:40 __init__.py

djc at enrai test $ cat pkg/__init__.py
djc at enrai test $ cat pkg/http.py
from http.client import HTTPConnection
djc at enrai test $ cat pkg/tests/__init__.py
from pkg.tests import http
djc at enrai test $ cat pkg/tests/http.py
from pkg import http
djc at enrai test $ python3
Python 3.2.3 (default, May 28 2012, 09:27:08)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pkg import http
>>>
djc at enrai test $ python3
Python 3.2.3 (default, May 28 2012, 09:27:08)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pkg.tests import http
>>>
djc at enrai test $ PYTHONPATH=. python3 pkg/tests/__init__.py
Traceback (most recent call last):
  File "pkg/tests/__init__.py", line 1, in <module>
    from pkg.tests import http
  File "/home/djc/src/test/pkg/tests/__init__.py", line 1, in <module>
    from pkg.tests import http
  File "/home/djc/src/test/pkg/tests/http.py", line 1, in <module>
    from pkg import http
  File "/home/djc/src/test/pkg/http.py", line 1, in <module>
    from http.client import HTTPConnection
  File "/home/djc/src/test/pkg/tests/http.py", line 1, in <module>
    from pkg import http
ImportError: cannot import name http

----------
components: Interpreter Core
messages: 176545
nosy: brett.cannon, djc, ncoghlan
priority: normal
severity: normal
status: open
title: Absolute imports fail to take full path into account?
versions: Python 3.2

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


More information about the New-bugs-announce mailing list