Skip to content

PLR5501 fix ate my comment! #9779

@akx

Description

@akx

plr5501-testcase.py

class Class:
    def can_do_thing(self, thing) -> bool:
        if self.thing_id == thing.id:
            return True
        if self.x:
            if self.y.z(thing):
                return True
        else:
            # This comment should not be eaten by automated fixes,
            # because it explains important context about the next if block.
            # I would be quite sad if it vanished, because I'm quite fond of it.
            if self.thing.color == thing.color_id:
                return True
        return False

ruff --select=PLR5501 --isolated --diff plr5501-testcase.py

--- plr5501-testcase.py
+++ plr5501-testcase.py
@@ -5,10 +5,6 @@
         if self.x:
             if self.y.z(thing):
                 return True
-        else:
-            # This comment should not be eaten by automated fixes,
-            # because it explains important context about the next if block.
-            # I would be quite sad if it vanished, because I'm quite fond of it.
-            if self.thing.color == thing.color_id:
-                return True
+        elif self.thing.color == thing.color_id:
+            return True
         return False

Other info

  • Ruff 0.2.0 on a Mac.
  • I really, really liked that comment. 😭
  • I guess the best thing to do is to move the comment inside the elif?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions