-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-self
] Ignore attribute accesses on instance-like variables …
…(`SLF001`) (#16149)
- Loading branch information
1 parent
aa88f2d
commit c814745
Showing
8 changed files
with
242 additions
and
133 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
crates/ruff_linter/resources/test/fixtures/flake8_self/SLF001_1.py
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,45 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Annotated | ||
|
||
# https://github.com/astral-sh/ruff/issues/9022 | ||
|
||
class Lorem[T]: | ||
def f(self): | ||
lorem_1 = Lorem() | ||
lorem_1._value = 1 # fine | ||
|
||
lorem_2 = Lorem[bytes]() | ||
lorem_2._value = 1 # fine | ||
|
||
|
||
class Ipsum: | ||
def __new__(cls): | ||
instance = super().__new__(cls) | ||
instance._value = 1 # fine | ||
|
||
|
||
class Dolor[T]: | ||
def f( | ||
self, | ||
a: Dolor, | ||
b: Dolor[int], | ||
c: Annotated[Dolor, ...], | ||
d: Annotated[Dolor[str], ...] | ||
): | ||
a._value = 1 # fine | ||
b._value = 1 # fine | ||
c._value = 1 # fine | ||
d._value = 1 # fine | ||
|
||
@classmethod | ||
def m(cls): | ||
instance = cls() | ||
instance._value = 1 # fine | ||
|
||
|
||
class M(type): | ||
@classmethod | ||
def f(mcs): | ||
cls = mcs() | ||
cls._value = 1 |
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
.../snapshots/ruff_linter__rules__flake8_self__tests__private-member-access_SLF001_1.py.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/flake8_self/mod.rs | ||
--- | ||
|
Oops, something went wrong.