flake8 plugin which enforces 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 as 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
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_clean_block-0.1.1.tar.gz
.
File metadata
- Download URL: flake8_clean_block-0.1.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41c2385b0c5fb71a68e0a0f4b95b47ef6487cb63e33f326b1980bc2a34fb46a0 |
|
MD5 | 4963a0613b0bfa1d67577aee3ae5b5a5 |
|
BLAKE2b-256 | c7b6b70b65ac1d2f6cbc1d30bfb0e2a0b1edeeba0d3ebf37ba0cd09f47613c6c |
File details
Details for the file flake8_clean_block-0.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: flake8_clean_block-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fca1e2743a423e2604da9c1cf810ccdd15cead8ac43913a87b9199ded085f902 |
|
MD5 | efa06f2dd6a31e241935eb6e083e7525 |
|
BLAKE2b-256 | 8072833e8782c87d2a5328b5083ffa06244898171a26028c9f8128b7a82e53ca |