New submission from Malcolm Smith:

https://docs.python.org/3/reference/simple_stmts.html#the-import-statement 
defers the full specification of relative imports to PEP 328. PEP 328 gives the 
example "from ...sys import path" in a second-level package, and notes "while 
that last case is legal, it is certainly discouraged".

However, in the current implementation it actually isn't legal. Using a stdlib 
second-level package to test:

Python 3.5.3 (default, Apr 10 2017, 07:53:16)  [GCC 6.3.0 64 bit (AMD64)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.dom
>>> __package__ = "xml.dom"
>>> from . import minidom  # Works fine
>>> from ...sys import path
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: attempted relative import beyond top-level package

Either the documentation or the implementation should be fixed.

----------
components: Interpreter Core
messages: 297608
nosy: Malcolm Smith
priority: normal
severity: normal
status: open
title: Contrary to documentation, relative imports cannot pass through the top 
level
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30840>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to