Changelog


← Back to all posts

November 10, 2021

New Refactorings

Remove empty nested block

Sourcery refactoring id: remove-empty-nested-block

Description:

Remove nested block which has no effect

Before:

for i in range(3):
    pass

After:

Here the code has been removed:

Explanation:

An if or for which is empty and has no effect should not be present in the code. It clutters things up and makes it harder to see what the code is really doing.

Simplify dictionary update

Sourcery refactoring id: simplify-dictionary-update

Description:

Add single value to dictionary directly rather than using update()

Before:

def foo(d: dict) -> None:
    d.update({"request": HttpRequest()})
    frobnicate(d)

After:

def foo(d: dict) -> None:
    d["request"] = HttpRequest()
    frobnicate(d)

Explanation:

When we are just adding one entry to a dictionary it is simpler to do it directly rather than via the update() method. This also eliminates the overhead of constructing another dictionary and calling a method, so should slightly improve performance.

Enhancements

  • We no longer suggest conversion to a generator on comprehensions inside str.join

Bug fixes

  • Fixed issue where metrics hover would show on the decorator line in VS Code
  • Fixed issue where we could incorrectly suggest remove-redundant-if if global state had changed.
  • Limited de-morgan inequality refactoring to numerical types
  • Fix issue where the scan for refactorings and detect clones commands sometimes failed to work on VS Code in Windows
  • Limit use-count refactoring to only apply on lists and strings