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/master?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.6 to 3.9 supported.

Installation

First, install with pip:

python -m pip install flake8-no-pep420

Second, check that flake8 lists the plugin in its version line:

$ flake8 --version
3.8.4 (flake8-no-pep420: 1.0.0, mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.8.0 on Darwin

Third, add the INP prefix to your select list. For example, if you have your configuration in setup.cfg:

[flake8]
select = E,F,W,INP

Linting a Django project? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.


Rationale

Implicit namespace packages are folders of Python files without an __init__.py. They’re valid and importable, but unfortunately they’re not discovered by many code quality tools:

Such silent failure leads to a false sense of security. 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 folder 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 on a Django project there’s the manage.py file. In these cases you should add # noqa: INP001 on the first line of the file.

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-1.0.1.tar.gz (11.3 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-1.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flake8-no-pep420-1.0.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/51.1.0.post20201221 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for flake8-no-pep420-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e1d91c8314c13887505c10d9cd70e0ff9b27dd112bf2fea59be29846bf1bfe6b
MD5 b294b8fc60ebe0090db23ba6977aaeab
BLAKE2b-256 8c4b7ee3ca29158c038a67f7beea20aeafd43e24f168721cf6a02bf889b8fed2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flake8_no_pep420-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/51.1.0.post20201221 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for flake8_no_pep420-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e0acaf000d4e6c9649dd1c30f3e1f9d0ef9bddbd376e07b97e4614344d8704b6
MD5 83ced603edeca0ba304d59770bca7088
BLAKE2b-256 19e4606e739f4a71efb089ef8ee4f704af1edc46cf1ab0377be44377a09a4caa

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