Skip to main content

A flake8 plugin that enforces a blank line after if/for/while/with/try blocks

Project description

flake8-clean-block

This is a flake8 plugin that enforces a blank line after if/for/while/with/try blocks in Python code.

Installation

pip install flake8-clean-block

Violation codes

There is one violation code that this plugin reports:

Code Description
CLB100 no blank line after the end of an indented block

Style examples

Wrong

This plugin considers the following styles wrong:

for i in range(5):
    print(i)
some_var = 2
for i in range(5):
    print(i)
if k == 2:
    print(k)
else:
    print("k")
for j in range(5):
    print(j)
for i in range(5): a += i
print(a)
with open('filename.txt', 'r') as fp:
    content = fp.readlines()
print(content)

Correct

Correspondingly, here are the correct styles, because they are easier to read and less error-prone:

for i in range(5):
    print(i)

some_var = 2
for i in range(5):
    print(i)

if k == 2:
    print(k)
else:
    print("k")

for j in range(5):
    print(j)
for i in range(5): a += i

print(a)
with open('filename.txt', 'r') as fp:
    content = fp.readlines()

print(content)

Rationale

When two lines belonging to different indentation level are right next to each other, it's difficult to read. Additionally, accidentally hitting the "tab" key on the outer line leads to subtle and hard-to-find bugs (and vice versa).

Therefore, it's better that we add at least one blank line between lines of different indentation levels.

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_clean_block-0.1.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

flake8_clean_block-0.1.2-py2.py3-none-any.whl (4.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file flake8_clean_block-0.1.2.tar.gz.

File metadata

  • Download URL: flake8_clean_block-0.1.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for flake8_clean_block-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0a1f8a58be210a013715810a78dda029a65660373f585b7e14e36c3b85c7791d
MD5 befce79be6d5900f9b86742dc7fe5e4a
BLAKE2b-256 31985a64a773cff79046fdad28eb25de18322d7d2e26e3895cd7c1abed8134fa

See more details on using hashes here.

File details

Details for the file flake8_clean_block-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_clean_block-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9684c26a6b087e25f73966fe8f4a38f6abb3e9737a9f781140115e0e2c14a93c
MD5 4dfaf1afecdee5eeef9888cfa974fccb
BLAKE2b-256 0bd3cc0037b86f87c1ec28fa970d7325e1b6b6ba54c26f853501d0c5e5d764df

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