A flake8 plugin to ban PEP-420 implicit namespace packages.
Project description
A flake8 plugin to ban PEP-420 implicit namespace packages.
Requirements
Python 3.6 to 3.10 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:
Django’s test runner
mypy without its –namespace-packages option
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flake8-no-pep420-1.1.1.tar.gz
.
File metadata
- Download URL: flake8-no-pep420-1.1.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f91b947851a472a43e6ba60952bab146a1e01c4c4edd01cc1da8216c00a4036c |
|
MD5 | c441b17e364f81ef4e91e16ff4d7a5ab |
|
BLAKE2b-256 | db0fb91ff401e9768219b80a222dc9ed22215c61fbcb8572005791b43a3fe90a |
File details
Details for the file flake8_no_pep420-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: flake8_no_pep420-1.1.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd14a1a78e82dd64ec1b3e45dd1da1cfd07a93c49808f68e6f7cf0ee6d3b80bf |
|
MD5 | fc4a9b14472974b0a501a0f459811d71 |
|
BLAKE2b-256 | 5815ac067af394f36c9ae05b9a749443a9b02ad9426235dcdf5010a67cad4b9c |