sourcery-ai / sourcery

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

`/=` Refactoring #308

Open Anselmoo opened 1 year ago

Anselmoo commented 1 year ago

Checklist

Description

Sourcery suggests -= and +=, however not /=.

Code Before

a = a / 2

Code After

a /= 2
Hellebore commented 1 year ago

Thanks for posting this - we'll add it to our backlog.

Hellebore commented 1 year ago

Oh hang on @Anselmoo - I do get suggested a conversion to /= as long as Sourcery can identify the type of the variable. Have you got a code snippet where we suggest += but not /= ?

Anselmoo commented 1 year ago

@Hellebore thx for giving me feedback. I had the issue once in a project, but unfortunately, don't find it yet.

However, I create the following four examples:

  1. No suggestions for refactoring
  2. No suggestions for refactoring
  3. Yes
  4. Shows that refactor and regular expression are the same

I hope it helps and that I don't miss anything.

image

https://gist.github.com/Anselmoo/f4763afb588cf0fda96255cba099c876

def cross_check() -> None:
    """Cross check with /= operator"""
    i: float = 1.0
    j: float = 1.0

    for _ in range(10):
        i = i / 2
        j /= 2
        print(i == j)