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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

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