Search code examples
pythonimportpylint

What is the difference between importing from `foo.py` and importing from `foo/__init__.py` in Python


If foo.py and foo/__init__.py are the same and do not contain relative import. And if you import with the following :

from foo import X #  (or import foo)

I thought there was no difference. I did that quite a number of time when a file become too big and when I want to burst it into a package and multiple files. But this is not really the case as evidenced by this commit failing the tests for pylint.

pylint/utils.py → pylint/utils/__init__.py
File renamed without changes.

It makes 3 functional tests fail (logging_format_interpolation, deprecated_methods_py3 and redundant_unittest_assert). This is true rebase after rebase and each time the commit from the master branch was working fine. I also use the --recreate option when launching tox.

The stdlib.py file that contain those checkers does not seem to even import something from pylint.utils (it uses pylint.checker.utils), so I have no idea why it would break, yet it does.

This file contain some function starting with an underscore (_function_name) could it be the problem ?


Solution

  • There is really no difference. The pylint master branch was just not passing the tests suite for a very long time, see this comment.