ruff
ruff copied to clipboard
[`pycodestyle`] Do not trigger `E3` rules on defs following a function/method with a dummy body
Summary
Closes #10211
This PR keeps track of functions with a dummy body, and does not trigger E301, E302 or E306 on defs following functions with a dummy body.
Test Plan
The code snippets from the issue have been added to the fixture.
On that note, so far the test cases for the E3 rules have been grouped by rule, since it made things easier when checking the results by hand. However it now makes it harder to review the snapshots (here nothing really changed, only line numbers), so I can add the new tests at the end of the fixture file if that makes things easier.
ruff-ecosystem results
Linter (stable)
✅ ecosystem check detected no linter changes.
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+0 -5 violations, +0 -0 fixes in 1 projects; 43 projects unchanged)
zulip/zulip (+0 -5 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
- scripts/lib/zulip_tools.py:601:1: E302 [*] Expected 2 blank lines, found 0 - zerver/decorator.py:556:1: E302 [*] Expected 2 blank lines, found 0 - zerver/lib/validator.py:268:1: E302 [*] Expected 2 blank lines, found 0 - zproject/config.py:33:1: E302 [*] Expected 2 blank lines, found 0 - zproject/config.py:56:1: E302 [*] Expected 2 blank lines, found 0
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| E302 | 5 | 0 | 5 | 0 | 0 |
Thanks for addressing the feedback. I overlooked this last time but the rule should continue to error if there's only one blank line between two functions (it should either be 0 or 2, but never 1). I found this in the ecosystem checks.
@overload
def components(models: dict[str, Model], wrap_script: bool = ..., # type: ignore[overload-overlap] # XXX: mypy bug
wrap_plot_info: Literal[True] = ..., theme: ThemeLike = ...) -> tuple[str, dict[str, str]]: ...
@overload
def components(models: dict[str, Model], wrap_script: bool = ..., wrap_plot_info: Literal[False] = ...,
theme: ThemeLike = ...) -> tuple[str, dict[str, RenderRoot]]: ...
def components(models: Model | Sequence[Model] | dict[str, Model], wrap_script: bool = True,
wrap_plot_info: bool = True, theme: ThemeLike = None) -> tuple[str, Any]:
''' Return HTML components to embed a Bokeh plot. The data for the plot is
stored directly in the returned HTML.
An example can be found in examples/embed/embed_multiple.py'''
This should error because there's only a single blank line between the implementation and the last @overload declaration.
I didn't think about that, I've fixed it in ad7e466.