Skip to main content

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

Project description

https://img.shields.io/github/workflow/status/adamchainz/flake8-no-pep420/CI/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.10 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 unfortunately they’re silently ignored by many tools, like:

Such silent failure leads to a false sense of security:

  • Tests may look legitimate but never run

  • Code may be untested but not affect 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.

flake8-no-pep420 will trigger this on the first line of any file that sits in a directory without a __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. As such, 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.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8_no_pep420-2.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file flake8-no-pep420-2.1.0.tar.gz.

File metadata

  • Download URL: flake8-no-pep420-2.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for flake8-no-pep420-2.1.0.tar.gz
Algorithm Hash digest
SHA256 dbbbba8124882e11fa30a2164f369078a8508a0b0359e203e4983d53598ca624
MD5 de2cacadcc6c9e1da0ff06eba8748935
BLAKE2b-256 43763889e59dd786e9505c5e47af085501e4bf9ef7d8ce36c9f1a8d5bca8316d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flake8_no_pep420-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for flake8_no_pep420-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d82088b125f2dda5a4e70b84ec5faad7465aed7c0efbcc29497350db2a28eee
MD5 9b6236eb91bb7ae9365879647787622f
BLAKE2b-256 5276bace2a3b05a7338a25f8206422d5432218a9339667f098b2cbe750394113

See more details on using hashes here.

Supported by

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