mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
[flake8-self
] Ignore attribute accesses on instance-like variables (SLF001
) (#16149)
This commit is contained in:
parent
aa88f2dbe5
commit
c814745643
8 changed files with 243 additions and 134 deletions
45
crates/ruff_linter/resources/test/fixtures/flake8_self/SLF001_1.py
vendored
Normal file
45
crates/ruff_linter/resources/test/fixtures/flake8_self/SLF001_1.py
vendored
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue