-
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.
Support local and dynamic class- and static-method decorators (#8592)
## Summary This brings ruff's behavior in line with what `pep8-naming` already does and thus closes #8397. I had initially implemented this to look at the last segment of a dotted path only when the entry in the `*-decorators` setting started with a `.`, but in the end I thought it's better to remain consistent w/ `pep8-naming` and doing a match against the last segment of the decorator name in any case. If you prefer to diverge from this in favor of less ambiguity in the configuration let me know and I'll change it so you would need to put e.g. `.expression` in the `classmethod-decorators` list. ## Test Plan Tested against the file in the issue linked below, plus the new testcase added in this PR.
- Loading branch information
1 parent
565ddeb
commit 4ebd0bd
Showing
8 changed files
with
279 additions
and
33 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
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
71 changes: 71 additions & 0 deletions
71
...ep8_naming/snapshots/ruff_linter__rules__pep8_naming__tests__staticmethod_decorators.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,71 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pep8_naming/mod.rs | ||
--- | ||
N805.py:7:20: N805 First argument of a method should be named `self` | ||
| | ||
6 | class Class: | ||
7 | def bad_method(this): | ||
| ^^^^ N805 | ||
8 | pass | ||
| | ||
|
||
N805.py:12:30: N805 First argument of a method should be named `self` | ||
| | ||
10 | if False: | ||
11 | | ||
12 | def extra_bad_method(this): | ||
| ^^^^ N805 | ||
13 | pass | ||
| | ||
|
||
N805.py:31:15: N805 First argument of a method should be named `self` | ||
| | ||
30 | @pydantic.validator | ||
31 | def lower(cls, my_field: str) -> str: | ||
| ^^^ N805 | ||
32 | pass | ||
| | ||
|
||
N805.py:35:15: N805 First argument of a method should be named `self` | ||
| | ||
34 | @pydantic.validator("my_field") | ||
35 | def lower(cls, my_field: str) -> str: | ||
| ^^^ N805 | ||
36 | pass | ||
| | ||
|
||
N805.py:64:29: N805 First argument of a method should be named `self` | ||
| | ||
62 | pass | ||
63 | | ||
64 | def bad_method_pos_only(this, blah, /, self, something: str): | ||
| ^^^^ N805 | ||
65 | pass | ||
| | ||
|
||
N805.py:70:13: N805 First argument of a method should be named `self` | ||
| | ||
68 | class ModelClass: | ||
69 | @hybrid_property | ||
70 | def bad(cls): | ||
| ^^^ N805 | ||
71 | pass | ||
| | ||
|
||
N805.py:78:13: N805 First argument of a method should be named `self` | ||
| | ||
77 | @bad.wtf | ||
78 | def bad(cls): | ||
| ^^^ N805 | ||
79 | pass | ||
| | ||
|
||
N805.py:86:14: N805 First argument of a method should be named `self` | ||
| | ||
85 | @good.expression | ||
86 | def good(cls): | ||
| ^^^ N805 | ||
87 | pass | ||
| | ||
|
||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.