A flake8 plugin to ban PEP-420 implicit namespace packages.
Linting a Django project? Check out my book Boost Your Django DX which covers Flake8 and many other code quality tools.
Requirements
Python 3.9 to 3.14 supported.
Installation
First, install with pip:
python -m pip install flake8-no-pep420
Second, if you define Flake8’s select setting, add the INP prefix to it. Otherwise, the plugin should be active by default.
Rationale
Implicit namespace packages are directories of Python files without an __init__.py. They’re valid and importable, but they break some tools:
unittest test discovery, unless -s (--start-directory) points to the namespace package. By extension, this affects Django’s test runner too.
Coverage.py, unless report.include_namespace_packages is enabled.
pytest (Issue #5147)
In most cases, tools fail silently, which can lead to a false sense of security:
Tests may look legitimate but never run
Code may be untested but not appear in coverage statistics
PEP-420’s algorithm is non-trivial which is probably why such tools haven’t (yet) implemented it.
Rules
INP001: File is part of an implicit namespace package. Add __init__.py?
flake8-no-pep420 will trigger this on the first line of any file that sits in a directory without an __init__.py file.
Often projects have a few root files not in packages, for which an __init__.py file should not be added. For example, Django projects normally have a manage.py file in the root of their repository. In these cases you can ignore the INP001 error. It’s possible to use # noqa: INP001 to ignore the error in-line, but this isn’t possible if the first line is a shebang, such as in Django’s manage.py. In such cases it’s preferable to use Flake8’s per-file-ignores option, for example in setup.cfg:
[flake8]
# ...
per-file-ignores =
manage.py:INP001
Metadata
Release files for flake8-no-pep420 2.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flake8_no_pep420-2.9.0.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flake8_no_pep420-2.9.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.3 kB
Release files / flake8_no_pep420-2.9.0.tar.gz
| Download URL | flake8_no_pep420-2.9.0.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5dcd9e23bdd545cb957dd23987d9d227e733d1610717b0e13591262df1a33413
|
|
BLAKE2b-256 checksum How to use checksums |
ace35373b9c21537efc9954c5daa924e9b59ff09ead43b5068f2b4b8ea8cde23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 8, 2025.
Transparency logRelease files / flake8_no_pep420-2.9.0-py3-none-any.whl
| Download URL | flake8_no_pep420-2.9.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
981d5d720dd545662f85625373badd4ca33a4e6484cc5ad976ca17d00dc994de
|
|
BLAKE2b-256 checksum How to use checksums |
92561f625d8399c3441e2976c8dfde6dd2af2319e216323c07e623e8086e9b65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 8, 2025.
Transparency log