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.
remove-redundant-fstring
Replace f-string with no interpolated values with string.
description = f"This is a totally normal string"
description = "This is a totally normal string"
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-fstring-formatting
Simplify unnecessary nesting, casting and constant values in f-strings
description = f'This {1} thing is {f"{str(adjective)}"}'
description = f"This 1 thing is {adjective}"
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
Replace boolean ternary with inline if expression
protocol_type = uses_ssl() and "https" or "http"
protocol_type = "https" if uses_ssl() else "http"
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.
# TODO Rename this here and in [first_usage] and [second_usage]
assign-if-exp
to cover the case where the default value is assigned
firstBefore:
x = 2
if condition:
x = 1
After:
x = 1 if condition else 2
default-get
refactorings now work for if expressionsuse-any
will no longer trigger if it introduces a short-circuit where global
state is writtenmerge-repeated-if
will no longer trigger if the first if
writes global
state that could affect the seconduse-any
will no longer trigger if the for loop target is used later on