-
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.
Improve compatibility between multi-statement PYI rules (#7024)
## Summary This PR modifies a few of our rules related to which statements (and how many) are allowed in function bodies within `.pyi` files, to improve compatibility with flake8-pyi and improve the interplay dynamics between them. Each change fixes a deviation from flake8-pyi: - We now always trigger the multi-statement rule (PYI048) regardless of whether one of the statements is a docstring. - We no longer trigger the `...` rule (PYI010) if the single statement is a docstring or a `pass` (since those are covered by other rules). - We no longer trigger the `...` rule (PYI010) if the function body contains multiple statements (since that's covered by PYI048). Closes #7021. ## Test Plan `cargo test`
- Loading branch information
1 parent
f7dca3d
commit 51d69b4
Showing
9 changed files
with
103 additions
and
64 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
def bar(): # OK | ||
... | ||
def bar(): | ||
... # OK | ||
|
||
|
||
def oof(): # OK, docstrings are handled by another rule | ||
def bar(): | ||
pass # OK | ||
|
||
|
||
def bar(): | ||
"""oof""" # OK | ||
|
||
|
||
def oof(): # ERROR PYI048 | ||
"""oof""" | ||
print("foo") | ||
|
||
|
||
def foo(): # Ok not in Stub file | ||
def foo(): # ERROR PYI048 | ||
"""foo""" | ||
print("foo") | ||
print("foo") | ||
|
||
|
||
def buzz(): # Ok not in Stub file | ||
def buzz(): # ERROR PYI048 | ||
print("fizz") | ||
print("buzz") | ||
print("test") |
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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
def bar(): ... # OK | ||
def bar(): | ||
... # OK | ||
|
||
|
||
def oof(): # OK, docstrings are handled by another rule | ||
"""oof""" | ||
print("foo") | ||
pass # OK | ||
|
||
def bar(): | ||
"""oof""" # OK | ||
|
||
def oof(): # ERROR PYI048 | ||
"""oof""" | ||
print("foo") | ||
|
||
def foo(): # ERROR PYI048 | ||
def foo(): # ERROR PYI048 | ||
"""foo""" | ||
print("foo") | ||
print("foo") | ||
|
||
|
||
def buzz(): # ERROR PYI048 | ||
def buzz(): # ERROR PYI048 | ||
print("fizz") | ||
print("buzz") | ||
print("test") |
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
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
24 changes: 19 additions & 5 deletions
24
...uff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI048_PYI048.pyi.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