[Import-SIG] an old idea: getting rid of __init__.py
ncoghlan at gmail.com
Tue May 5 09:49:19 CEST 2015
On 3 May 2015 at 08:22, Eric Snow <ericsnowcurrently at gmail.com> wrote:
> When namespace packages were under discussion I remember we were
> seriously considering eliminating the requirement of __init__.py for
> *all* packages.
Which is what we effectively did. You only need an __init__.py now if you:
a) want module level attributes, rather than only subpackages;
b) want to run other code at package import time; or
c) want to forcibly close the package to further extension in other directories.
As Antoine notes, the implicit nature of magically scanning
directories for subpackages trades away comprehensibility for the sake
of convenience. It's main advantage is actually "that's the way other
languages handle import namespacing".
The kind of traditional package created by adding __init__.py could be
described as being more akin to a "directory module" than it is to a
pure namespace package (certainly "directory module" is an accurate
description of former single-file modules like unittest, which go out
of their way to hide the fact that they're now implemented across
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Import-SIG