Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLR5501 fix ate my comment! #9779

Open
akx opened this issue Feb 2, 2024 · 2 comments
Open

PLR5501 fix ate my comment! #9779

akx opened this issue Feb 2, 2024 · 2 comments
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@akx
Copy link
Contributor

akx commented Feb 2, 2024

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?
@AlexWaygood AlexWaygood added bug Something isn't working fixes Related to suggested fixes for violations labels Feb 2, 2024
@zanieb
Copy link
Member

zanieb commented Feb 2, 2024

Sorry! We're trying to figure out what fix safety looks like with dropping comments. Retaining comments is really hard and we'd need to invest quite a bit to never drop them, but we're hoping to have a way to treat fixes as unsafe if there's a comment in the edit range.

@zanieb
Copy link
Member

zanieb commented Feb 2, 2024

Tracking this in #9790

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations
Projects
None yet
Development

No branches or pull requests

3 participants