Skip to main content

Flake8-plus

CircleCI codecov license pypi black

Flake8-plus is a plugin for Flake8 that detects incorrect amounts of vertical whitespace before the first toplevel import statement, before return statements and before except. The plugin can be configured to expect any number of blank lines. By default, the plugin expects no blank lines before both the import and return statements, and the except keyword.

Installation

Flake8-plus can be installed from PyPI using pip:

$ pip install flake8-plus

You can verify that it has been installed as follows (the version numbers you see may vary):

$ flake8 --version
5.0.4 (flake8-plus: 0.1.0, mccabe: 0.7.0, pycodestyle: 2.9.1, pyflakes: 2.5.0)

Configuration

You can set the required number of blank lines before the first import as well as the number of blank lines required before a return and before except. This can be done from the command line:

$ flake8 --blanks-before-imports 1 --blanks-before-return 1 --blanks-before-except 1

Or from one of the setup.cfg, tox.ini, or .flake8 files:

[flake8]
blanks-before-imports=1
blanks-before-return=1
blanks-before-except=1

Why no blank lines?

Before import

Neither Black, Flake8 nor Pylint enforces a specific number of blank lines preceding the first import and consequently there seems to be no consensus or standard. The table below shows the frequency of the number of blank lines before the first toplevel import statement in the code bases for Black, Flake8 and Pylint (as of October 2022).

Package Total files 0 blanks 1 blank 2 blanks Folder
Black 33 21 12 0 src
Flake8 32 32 0 0 src/flake8/
Pylint 177 3 170 4 pylint

Clearly, there is no real consensus. Black seems undecided, Flake8 consistently uses 0 blanks, and Pylint seems to prefer 1 blank line. However, it's worth noting that the Pylint code does not consistently include module docstrings (thereby breaking pylint(missing-module-docstring)). For that reason, and also because this is a Flake8 plugin, the plugin follows the style of Flake8 as the default.

Before return

Neither Black, Flake8 nor Pylint enforces a specific number of blank lines preceding return. However, they all use zero blank lines more frequently than they use any other number of blanks. The table below shows the frequency of the number of blank lines before a return statement in the code bases for Black, Flake8 and Pylint (as of October 2022).

Package Total returns 0 blanks 1 blank 2 blanks Folder
Black 618 544 74 0 src
Flake8 174 155 19 0 src/flake8/
Pylint 1941 1852 89 0 pylint

Since zero blank lines is the style used most frequently, Flake8-plus uses that as that as the default.

Before except

Neither Black, Flake8 nor Pylint enforces a specific number of blank lines preceding except. However, they all use zero blank lines more frequently than they use any other number of blanks. The table below shows the frequency of the number of blank lines before an except statement in the code bases for Black, Flake8 and Pylint (as of October 2022).

Package Total excepts 0 blanks 1 blank 2 blanks Folder
Black 71 64 7 0 src
Flake8 26 26 0 0 src/flake8/
Pylint 285 283 2 0 pylint

Since zero blank lines is the style used most frequently, Flake8-plus uses that as that as the default.

Reported problems

Code  Description
PLU001 "expected {} blank lines before first import, found {}"
PLU002 "expected {} blank lines before return statement, found {}"
PLU003 "expected {} blank lines before except, found {}"

Download files

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

Source Distribution

flake8-plus-0.5.0.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_plus-0.5.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file flake8-plus-0.5.0.tar.gz.

File metadata

  • Download URL: flake8-plus-0.5.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for flake8-plus-0.5.0.tar.gz
Algorithm Hash digest
SHA256 db0f9bae5cc387960d94ff1059424a45bbdc7a41e8f8cf32cb75b9c0b381016b
MD5 4a14142accd34c90e102c72a40e49bd5
BLAKE2b-256 504aad6b1685aa0a5a0a5348b587e13c18851e5d525af006f399e80485afed8b

See more details on using hashes here.

File details

Details for the file flake8_plus-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: flake8_plus-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for flake8_plus-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 145cbfdb714bc92bf38e1aeecd43de17eebfbe27671bb27c3d35a8406514fce0
MD5 ab19dc70f20c95ed22bdd0f4f4673282
BLAKE2b-256 655d0d3d0ccb5a4db1bf772f95f1337a65b16616bdde3b7ac9f5d9c1d1ae8144

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 Sentry Error logging StatusPage Status page