New submission from Darren Dale <dsdal...@gmail.com>:

Old-style relative imports have been strongly discouraged in some sections of 
the python documentation. This was discussed on the python-dev mailing list. 
Executive summary: "The issue is implementing a PEP with nice support for 
relative imports, and then documenting that it should never be used." To which 
Guido responded:

---
"Isn't this mostly historical? Until the new relative-import syntax was
implemented there were various problems with relative imports. The
short-term solution was to recommend not using them. The long-term
solution was to implement an unambiguous syntax. Now it is time to
withdraw the anti-recommendation. Of course, without going overboard
-- I still find them an acquired taste; but they have their place."
---

It was suggested I open a ticket and suggest specific changes. They are listed 
below:

The faq at
http://docs.python.org/py3k/faq/programming.html#what-are-the-best-practices-for-using-import-in-a-module
could go from:

"Never use relative package imports. If you’re writing code that’s in the 
package.sub.m1 module and want to import package.sub.m2, do not just write from 
. import m2, even though it’s legal. Write from package.sub import m2 instead. 
See PEP 328 for details."

to:

"Although the python community generally prefers absolute imports, relative 
imports may be useful in certain circumstances. See PEP 328 for details."



The programming faq for python-2.7 at
http://docs.python.org/faq/programming.html#what-are-the-best-practices-for-using-import-in-a-module
could go from:

"Never use relative package imports. If you’re writing code that’s in the 
package.sub.m1 module and want to import package.sub.m2, do not just write 
import m2, even though it’s legal. Write from package.sub import m2 instead. 
Relative imports can lead to a module being initialized twice, leading to 
confusing bugs. See PEP 328 for details."

to:

"Although the python community generally prefers absolute imports, relative 
imports may be useful in certain circumstances. Support for relative imports 
has recently been improved, and the use of the old-style relative imports is 
strongly discouraged. See PEP 328 for details."

There is also this warning against relative imports in PEP 8, that could go 
from:

   - Relative imports for intra-package imports are highly discouraged.
     Always use the absolute package path for all imports.
     Even now that PEP 328 [7] is fully implemented in Python 2.5,
     its style of explicit relative imports is actively discouraged;
     absolute imports are more portable and usually more readable.

to:

   - While the python community generally prefers absolute imports,
     relative imports may be useful in certain circumstances. Now that
     PEP 328 [7] is fully implemented in Python 2.5 and later, the
     older style of implicit relative imports is strongly discouraged.

----------
assignee: d...@python
components: Documentation
messages: 118031
nosy: d...@python, dsdale24
priority: normal
severity: normal
status: open
title: Withdraw anti-recommendation of relative imports from documentation
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3

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

Reply via email to