Skip to main content

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.

Release files for flake8-clean-block 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-clean-block 0.1.2
File Size Uploaded
flake8_clean_block-0.1.2.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-clean-block 0.1.2
File Interpreter ABI Platform
flake8_clean_block-0.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 7.9 kB

Release files / flake8_clean_block-0.1.2.tar.gz

Download URL flake8_clean_block-0.1.2.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0a1f8a58be210a013715810a78dda029a65660373f585b7e14e36c3b85c7791d
BLAKE2b-256 checksum
How to use checksums
31985a64a773cff79046fdad28eb25de18322d7d2e26e3895cd7c1abed8134fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / flake8_clean_block-0.1.2-py2.py3-none-any.whl

Download URL flake8_clean_block-0.1.2-py2.py3-none-any.whl
Size 4.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9684c26a6b087e25f73966fe8f4a38f6abb3e9737a9f781140115e0e2c14a93c
BLAKE2b-256 checksum
How to use checksums
0bd3cc0037b86f87c1ec28fa970d7325e1b6b6ba54c26f853501d0c5e5d764df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page