sourcery icon indicating copy to clipboard operation
sourcery copied to clipboard

`/=` Refactoring

Open Anselmoo opened this issue 3 years ago • 3 comments

Checklist

  • [x] I think this refactoring is useful for everyone (if it's too specific, consider a custom rule)
  • [x] Didn't find a similar issue

Description

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

Code Before

a = a / 2

Code After

a /= 2

Anselmoo avatar Nov 30 '22 19:11 Anselmoo

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

Hellebore avatar Dec 01 '22 10:12 Hellebore

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 /= ?

Hellebore avatar Feb 09 '23 11:02 Hellebore

@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)

Anselmoo avatar Feb 09 '23 16:02 Anselmoo