Skip to content

Commit

Permalink
use actual precedence based checks for parens in PLC2801. fixes astra…
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamsk committed Jan 27, 2025
1 parent cb3361e commit 991aec1
Show file tree
Hide file tree
Showing 3 changed files with 763 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@
# Calls
print(a.__call__()) # PLC2801 (no fix, intentional)

class Foo:
def __init__(self, v):
self.v = v

def __add__(self, other):
self.v += other
return self

def get_v(self):
return self.v

foo = Foo(1)
foo.__add__(2).get_v() # PLC2801


# Lambda expressions
blah = lambda: a.__add__(1) # PLC2801

Expand All @@ -72,13 +87,22 @@

# Subscripts
print({"a": a.__add__(1)}["a"]) # PLC2801
# https://github.com/astral-sh/ruff/issues/15745
print("x".__add__("y")[0]) # PLC2801

# Starred
print(*[a.__add__(1)]) # PLC2801

list1 = [1, 2, 3]
list2 = [4, 5, 6]
print([*list1.__add__(list2)]) # PLC2801

# Slices
print([a.__add__(1), a.__sub__(1)][0:1]) # PLC2801

# Attribute access
# https://github.com/astral-sh/ruff/issues/15745
print(1j.__add__(1.0).real) # PLC2801

class Thing:
def __init__(self, stuff: Any) -> None:
Expand Down
Loading

0 comments on commit 991aec1

Please sign in to comment.