-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
pycodestyle
]: Make blank lines in typing stub files optional (`E3*…
…`) (#10098) ## Summary Fixes #10039 The [recommendation for typing stub files](https://typing.readthedocs.io/en/latest/source/stubs.html#blank-lines) is to use **one** blank line to group related definitions and otherwise omit blank lines. The newly added blank line rules (`E3*`) didn't account for typing stub files and enforced two empty lines at the top level and one empty line otherwise, making it impossible to group related definitions. This PR implements the `E3*` rules to: * Not enforce blank lines. The use of blank lines in typing definitions is entirely up to the user. * Allow at most one empty line, including between top level statements. ## Test Plan Added unit tests (It may look odd that many snapshots are empty but the point is that the rule should no longer emit diagnostics)
- Loading branch information
1 parent
46ab9de
commit af6ea2f
Showing
12 changed files
with
577 additions
and
12 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
crates/ruff_linter/resources/test/fixtures/pycodestyle/E30.pyi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import json | ||
|
||
from typing import Any, Sequence | ||
|
||
class MissingCommand(TypeError): ... | ||
class AnoherClass: ... | ||
|
||
def a(): ... | ||
|
||
@overload | ||
def a(arg: int): ... | ||
|
||
@overload | ||
def a(arg: int, name: str): ... | ||
|
||
|
||
def grouped1(): ... | ||
def grouped2(): ... | ||
def grouped3( ): ... | ||
|
||
|
||
class BackendProxy: | ||
backend_module: str | ||
backend_object: str | None | ||
backend: Any | ||
|
||
def grouped1(): ... | ||
def grouped2(): ... | ||
def grouped3( ): ... | ||
@decorated | ||
|
||
def with_blank_line(): ... | ||
|
||
|
||
def ungrouped(): ... | ||
a = "test" | ||
|
||
def function_def(): | ||
pass | ||
b = "test" | ||
|
||
|
||
def outer(): | ||
def inner(): | ||
pass | ||
def inner2(): | ||
pass | ||
|
||
class Foo: ... | ||
class Bar: ... |
62 changes: 62 additions & 0 deletions
62
crates/ruff_linter/resources/test/fixtures/pycodestyle/E30_isort.pyi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import json | ||
|
||
|
||
|
||
from typing import Any, Sequence | ||
|
||
|
||
class MissingCommand(TypeError): ... # noqa: N818 | ||
|
||
|
||
class BackendProxy: | ||
backend_module: str | ||
backend_object: str | None | ||
backend: Any | ||
|
||
|
||
if __name__ == "__main__": | ||
import abcd | ||
|
||
|
||
abcd.foo() | ||
|
||
def __init__(self, backend_module: str, backend_obj: str | None) -> None: ... | ||
|
||
if TYPE_CHECKING: | ||
import os | ||
|
||
|
||
|
||
from typing_extensions import TypeAlias | ||
|
||
|
||
abcd.foo() | ||
|
||
def __call__(self, name: str, *args: Any, **kwargs: Any) -> Any: | ||
... | ||
|
||
if TYPE_CHECKING: | ||
from typing_extensions import TypeAlias | ||
|
||
def __call__2(self, name: str, *args: Any, **kwargs: Any) -> Any: | ||
... | ||
|
||
|
||
def _exit(self) -> None: ... | ||
|
||
|
||
def _optional_commands(self) -> dict[str, bool]: ... | ||
|
||
|
||
def run(argv: Sequence[str]) -> int: ... | ||
|
||
|
||
def read_line(fd: int = 0) -> bytearray: ... | ||
|
||
|
||
def flush() -> None: ... | ||
|
||
|
||
from typing import Any, Sequence | ||
|
||
class MissingCommand(TypeError): ... # noqa: N818 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...style/snapshots/ruff_linter__rules__pycodestyle__tests__blank_lines_E301_typing_stub.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
|
4 changes: 4 additions & 0 deletions
4
...style/snapshots/ruff_linter__rules__pycodestyle__tests__blank_lines_E302_typing_stub.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
|
Oops, something went wrong.