Skip to main content

A flake8 plugin to ban PEP-420 implicit namespace packages.

Project description

https://img.shields.io/github/actions/workflow/status/adamchainz/flake8-no-pep420/main.yml?branch=main&style=for-the-badge https://img.shields.io/pypi/v/flake8-no-pep420.svg?style=for-the-badge https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge pre-commit

A flake8 plugin to ban PEP-420 implicit namespace packages.

Requirements

Python 3.7 to 3.12 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.


Linting a Django project? Check out my book Boost Your Django DX which covers Flake8 and many other code quality tools.


Rationale

Implicit namespace packages are directories of Python files without an __init__.py. They’re valid and importable, but they break many tools, such as:

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

  • Types may never be checked

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8_no_pep420-2.6.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

flake8_no_pep420-2.6.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file flake8_no_pep420-2.6.0.tar.gz.

File metadata

  • Download URL: flake8_no_pep420-2.6.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for flake8_no_pep420-2.6.0.tar.gz
Algorithm Hash digest
SHA256 e4b0b469e087e40ea0f53cabf4b23f085dff095ba2f0dfe3d4f011de2f05d461
MD5 135bcf5271ede2328497c4d3cd37eec8
BLAKE2b-256 6fc08887019fc82898ff6b02ecf847603e0b7d94e337c9bccc4b85581b67f0c1

See more details on using hashes here.

File details

Details for the file flake8_no_pep420-2.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_no_pep420-2.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8174794e2ae79e8c76d520dfe5ab897c9830e908aa710731a069ab5fdbff24d9
MD5 52c3a5086f6418ee4d1186bb0020cbfa
BLAKE2b-256 907715b107157b8da826b480c6089ee20d106ce5bb3a55a73611c136080b1197

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page