[Python-Dev] Why does PEP 8 advise against explicit relative imports? (original) (raw)
Terry Reedy tjreedy at udel.edu
Tue Jul 16 23:27:37 CEST 2013
- Previous message: [Python-Dev] Why does PEP 8 advise against explicit relative imports?
- Next message: [Python-Dev] cpython: Issue #18408: Fix fileio_read() on _PyBytes_Resize() failure
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 7/16/2013 7:40 AM, Nick Coghlan wrote:
PEP 8 advises developers to use absolute imports rather than explicit relative imports.
Why? Using absolute imports couple the internal implementation of a package to its public name - you can't just change the top level directory name any more, you have to go through and change all the absolute imports as well. You also can't easily vendor a package that uses absolute imports inside another project either, since all the absolute imports will break. What's the concrete benefit of using absolute imports that overcomes these significant shortcomings in maintainability and composability?
From my viewpoint, absolute imports always work, on all python versions, whereas people have reported various problems with relative imports on python-list. At least some of the complaints were valid, at least at the time, but I have not paid too much attention.
Even if idlelib files used relative imports, 'idlelib' cannot change and I see no reason to ever change 'idle_test'. I would like to change camelCaseFileNames.py, but if ever done, that would affect both types of imports.
-- Terry Jan Reedy
- Previous message: [Python-Dev] Why does PEP 8 advise against explicit relative imports?
- Next message: [Python-Dev] cpython: Issue #18408: Fix fileio_read() on _PyBytes_Resize() failure
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]