blank-line-before-assignment¶
Require separators before assignments that do not continue the local flow.
Message¶
Missing blank line before assignment statement that follows a non-assignment statement.
Settings¶
| Setting | Description | Type | Default |
|---|---|---|---|
| allow_local_helper_capture | Allow local helper assignments that capture values from preceding code. | bool | True |
| allow_post_guard_continuation | Allow assignments that continue immediately after a guard statement. | bool | False |
| related_use_lookahead | Number of following statements inspected for assignment-related usage. | int | 2 |
| short_control_flow_max_statements | Maximum short control-flow size allowed before a following assignment. | int | 3 |
Valid examples¶
def f() -> int:
value = 1
other = value + 1
return other
Show more
def f() -> int:
log_start()
value = compute()
log_value(value)
return value
def f() -> int:
total = 0
total += 1
return total
def f() -> int:
"""Compute value."""
value = compute()
return value
def f(backend: object, archiver: object, writer: object) -> None:
if needs_status:
log_status(backend=backend, archiver=archiver, writer=writer)
last_status_time = loop.time()
def f() -> None:
if needs_status:
log_status()
update_metrics()
last_status_time = loop.time()
def f() -> None:
if needs_status:
log_status()
update_metrics()
refresh_cache()
last_status_time = loop.time()
async def f() -> None:
try:
work()
except Exception:
cleanup_a()
cleanup_b()
await cleanup_c()
collector_id = None
raise
async def f() -> None:
try:
work()
except Exception:
cleanup()
state = None
log_error()
raise
def f(output: object) -> None:
output.write("ok")
bar = output.bars["task"]
assert bar.n == 1
def f() -> None:
assert output.exists()
payload = json.loads(output.read_text())
assert "themes" in payload
def f(name: str | None) -> object:
configure_logging()
logger_name = "default" if name is None else name
return make_logger(logger_name)
def f(candidate: object, parser_input: str, style: object) -> object:
validate(candidate)
display_value = parser_input or str(candidate)
if supports_live_interaction():
highlight(display_value, style)
else:
summarize(display_value, style)
return candidate
def f(monkeypatch: object) -> dict[str, object]:
monkeypatch.setenv("TOKEN", "abc")
calls: dict[str, object] = {}
class FakeRepo:
def __init__(self) -> None:
calls["created"] = True
return calls
def f(logger: logging.Logger, handler: logging.Handler) -> None:
logger.addHandler(handler)
logger.propagate = False
def f() -> int:
log_start()
value = compute()
return value
Invalid examples¶
def f(values: list[int]) -> int:
total = 0
if values:
total += len(values)
total += 1
return total
Suggested fix
def f(values: list[int]) -> int:
total = 0
if values:
total += len(values)
total += 1
return total
Show more
def f(flag: bool, value: str) -> str:
if not flag:
return value
normalized = value.strip()
return normalized
Suggested fix
def f(flag: bool, value: str) -> str:
if not flag:
return value
normalized = value.strip()
return normalized
def f(value: int) -> int:
if value > 0:
log_status(value)
update_metrics(value)
adjusted = value + 1
return adjusted
return value
Suggested fix
def f(value: int) -> int:
if value > 0:
log_status(value)
update_metrics(value)
adjusted = value + 1
return adjusted
return value
def f() -> None:
if needs_status:
log_status()
last_status_time = loop.time()
Suggested fix
def f() -> None:
if needs_status:
log_status()
last_status_time = loop.time()
def f(candidate: object) -> object:
validate(candidate)
display_value = str(candidate)
if supports_live_interaction():
highlight(candidate)
return candidate
Suggested fix
def f(candidate: object) -> object:
validate(candidate)
display_value = str(candidate)
if supports_live_interaction():
highlight(candidate)
return candidate
def f(logger: logging.Logger, handler: logging.Handler) -> None:
logger.addHandler(handler)
logger.propagate = False
Suggested fix
def f(logger: logging.Logger, handler: logging.Handler) -> None:
logger.addHandler(handler)
logger.propagate = False
def f() -> int:
log_start()
value = compute()
return value
Suggested fix
def f() -> int:
log_start()
value = compute()
return value