[pycodestyle] Do not trigger E3 rules on defs following a function/method with a dummy body#10704
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| E302 | 5 | 0 | 5 | 0 | 0 |
| && !(state.follows.is_any_def() && line.last_token != TokenKind::Colon) | ||
| // Allow a function/method to follow a function/method with a dummy body. | ||
| && !matches!(state.follows, Follows::DummyDef) |
There was a problem hiding this comment.
Nit: It might be worth extracting this check into a small helper function to avoid repeating it three times (and it gives as the opportunity to give it a meaningful name).
|
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 |
Do not allow a single blank line between overloads and function.
|
I didn't think about that, I've fixed it in ad7e466. |
Summary
Closes #10211
This PR keeps track of functions with a dummy body, and does not trigger
E301,E302orE306on 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
E3rules 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.