sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.51k stars 65 forks source link

Comments aggressively removed in refactoring #280

Closed vigilyn closed 1 year ago

vigilyn commented 1 year ago

Description

Sourcery should not remove comments.

Original code

def some_function(event):
    # league_id is actually stored in event's "id" key and not league_id key
    league_id = event.get("id")
    if league_id:
        res.league_id = league_id

Sourcery Suggested refactoring (use-named-expression)

def some_function(event):
-    # league_id is actually stored in event's "id" key and not league_id key
-    league_id = event.get("id")
-    if league_id:
+    if league_id := event.get("id")
        res.league_id = league_id

Actual Desired refactoring (use-named-expression)

def some_function(event):
     # league_id is actually stored in event's "id" key and not league_id key
-    league_id = event.get("id")
-    if league_id:
+    if league_id := event.get("id")
        res.league_id = league_id

Debug Information

IDE Version: PyCharm 2022.2.1 (Professional Edition) Build #PY-222.3739.56, built on August 16, 2022 Runtime version: 17.0.3+7-b469.37 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

Sourcery Version: sourcery.pycharm-plugin (0.12.8)

Operating system and Version: macOS 12.6

Hellebore commented 1 year ago

This will be addressed by the new engine.

Danie-1 commented 10 months ago

In general, inline comments also seem to be removed. For example:

var1 = "World!"
var2 = "Hello {}".format(var1)  # a comment

becomes:

var1 = "World!"
var2 = f"Hello {var1}"

EDIT: I just saw that comments are mentioned in the FAQ