blank-line-after-control-block¶
Require separation after multiline control-flow block statements.
Message¶
Missing blank line after multiline control-flow block statement.
Settings¶
| Setting | Description | Type | Default |
|---|---|---|---|
| allow_compact_guard_ladders | Allow compact guard-ladder control-flow blocks without an extra blank line. | bool | True |
| allow_pytest_raises_clusters | Allow adjacent pytest.raises blocks that form one test cluster. | bool | True |
| allow_with_immediate_inspection | Allow a with block followed immediately by inspection of its bound value. | bool | True |
| related_use_lookahead | Number of following statements inspected for related value usage. | int | 2 |
Valid examples¶
def f(value: int) -> int:
if value > 0:
value += 1
return value
Show more
def f(value: int) -> int:
if value > 0:
value += 1
# comment separator
return value
def f(value: int) -> int:
if value > 0: return value
return 0
def load_config(text: str, format_name: str) -> object:
if format_name == "json":
return json.loads(text)
if format_name == "toml":
return tomllib.loads(text)
if format_name == "yaml":
return _load_yaml_text(text)
raise ValueError(format_name)
def normalize(parts: list[str], values: list[str]) -> None:
for part in values:
if part == "..":
parts.pop()
continue
parts.append(part)
def render(parser: object, capsys: object) -> object:
try:
parser.run()
except SystemExit:
pass
out = capsys.readouterr()
return out
def f() -> None:
with pytest.raises(ValueError):
parse("x")
with pytest.raises(TypeError):
parse(3)
def f(path: str) -> None:
with open(path) as handle:
content = handle.read()
assert content
def f(width: int | None, columns: list[str]) -> list[str]:
if width is not None:
template = f"{width:02d}"
columns.append(template)
columns.append(template if width is not None else "default")
return columns
def f(flag: bool, label: str) -> str:
if not flag:
return label
cleaned = label.strip()
return cleaned
def f(shell_name: str, interactive: bool) -> list[str]:
if shell_name == "zsh":
return ["-lic"]
if interactive:
return ["-ic"]
return ["-lc"]
def f(primary: str | None, fallback: str | None) -> str:
if primary is not None:
return primary
if fallback is not None:
return fallback
return "guest"
Invalid examples¶
def f(value: int) -> int:
if value > 0:
value += 1
return value
Suggested fix
def f(value: int) -> int:
if value > 0:
value += 1
return value
Show more
def f(values: list[int]) -> int:
total = 0
for value in values:
total += value
return total
Suggested fix
def f(values: list[int]) -> int:
total = 0
for value in values:
total += value
return total
def f(value: int, other: int) -> int:
if value > 0:
log(value)
audit(value)
return value
if other > 0:
return other
return 0
Suggested fix
def f(value: int, other: int) -> int:
if value > 0:
log(value)
audit(value)
return value
if other > 0:
return other
return 0
def f(flag: bool, label: str) -> str:
if not flag:
return label
return label.strip()
Suggested fix
def f(flag: bool, label: str) -> str:
if not flag:
return label
return label.strip()