This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Patrick Maupin
Recipients J Richard Snape, Patrick Maupin, brett.cannon, docs@python, eric.snow, flatsieve, ncoghlan
Date 2015-10-03.19:21:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1443900082.33.0.0454540957331.issue25294@psf.upfronthosting.co.za>
In-reply-to
Content
The PEP 8 recommendation to "use absolute imports" is completely, totally, unambiguously meaningless absent the expectation that packages refer to parts of themselves.  And it works, too!  (For a single level of package.)

As soon as packages are nested, this recommendation falls over, with the most innocuous code:

    x/__init__.py: import x.y
    x/y/__init__.py: import x.y.z; x.y.z
    x/y/z/__init__.py: <empty>

The ability to nest packages is an attractive nuisance from a programmer's perspective.  He's neatly organized his code, and now he finds that there are two ways to make it work:  (1) Use the disparaged relative imports; or (2) flatten his package to a single level, because importing X.Z from within X.Y will work fine.

IMO, the language that Nick proposes for PEP 8 will either (a) not be understood at all by the frustrated junior programmer -- sure, the import system views it as a circular import, but he's not seeing it that way; or (b) be understood to expose a huge wart on the side of Python:  Even though Z is only used by Y/__init__, and doesn't itself use anything else in Y, it cannot live alongside Y/__init__. Instead, unless Y is a top level module or the programmer uses denigrated relative imports, he will now have to move it to a different place, so that from Y he can then "import X.Y_HELPER.Z".

Another PEP 8 prescription is that "Standard library code should avoid complex package layouts and always use absolute imports."  Here's a serious offer -- I'll give $200 to whoever gets the patch accepted that makes lib2to3 conformant without breaking it.
History
Date User Action Args
2015-10-03 19:21:22Patrick Maupinsetrecipients: + Patrick Maupin, brett.cannon, ncoghlan, docs@python, eric.snow, flatsieve, J Richard Snape
2015-10-03 19:21:22Patrick Maupinsetmessageid: <1443900082.33.0.0454540957331.issue25294@psf.upfronthosting.co.za>
2015-10-03 19:21:22Patrick Maupinlinkissue25294 messages
2015-10-03 19:21:21Patrick Maupincreate