Some packages have
__init__.py files containing actual implementations of functions or classes. There are also very famous projects adopting this practice:
I was wondering what are the pros and cons of this practice and when it should be adopted.
I’ve searched online, but it seems that there is not a clear indication or a best practice. A lot of people suggest limiting the content of the
__init__.py to essential things, using them only to structure your package.
I understand that this approach makes clearer interfaces of your module, especially if you have very small modules, with a very limited number of simple classes and functions. On the other hand, if you have a very large number of modules and all the implementations are in the
__init__.py files, you will end having several files with the same name and probably you have to work on them at the same time; moreover, the size of the files can easily get out of hand and make them difficult to read and mantain.
Is there a best practice or at least a rule of thumb here? Is there any interesting reading or discussion on this topic?