Beta builds, refactorings and bug fixes


Beta builds on profile page

Beta build sign-up

You can now sign up on the website to get access to Sourcery’s beta updates. Just log in, go to your profile page and check the box under the ‘Nightly builds’ heading.

This will let you try out our latest refactorings and fixes the day they become available, rather than waiting for our plugin releases. Each morning when a build is available it will get automatically downloaded, then will prompt you to restart your IDE to get the new features.

New refactorings

Remove redundant f-string

Sourcery refactoring id: remove-redundant-fstring

Description:

Replace f-string with no interpolated values with string.

Before:

description = f"This is a totally normal string"

After:

description = "This is a totally normal string"

Explanation:

This refactoring spots cases where use of an f-string is unnecessary since there are no interpolated values. It’s easy to forget to remove the f if you have such a value and then remove it later.

Simplify f-string formatting

Sourcery refactoring id: simplify-fstring-formatting

Description:

Simplify unnecessary nesting, casting and constant values in f-strings

Before:

description = f"This {1} thing is {f'{str(adjective)}'}"

After:

description = f"This 1 thing is {adjective}"

Explanation:

When writing an f-string it is not necessary to interpolate the values of constants or cast variables to strings - these will be done automatically. It is also not necessary to nest f-strings when adding the contents of the nested string directly achieves the same result.

Ternary to If Expression

Sourcery refactoring id: ternary-to-if-expression

Description:

Replace boolean ternary with inline if expression

Before:

protocol_type = uses_ssl() and "https" or "http"

After:

protocol_type = "https" if uses_ssl() else "http"

Explanation:

In some cases, especially in old codebases that were written in Python 2, boolean expressions are used as ternary operators. However, replacing boolean ternary expressions with inline ifs where appropriate better portrays the code’s intention and therefore makes it easier for others to read it.

Enhancements

Before:

x = 2
if condition:
    x = 1

After:

x = 1 if condition else 2

Bug fixes