Refactorings that add imports, plus comments!
Added
-
Comments: Sourcery will now spot issues in your code that don’t have an automated code fix. Instead we will give a detailed explanation of the issue along with a guide on how to fix them. Just hover for more info. The first comment that we have introduced is
raise-specific-error
- here we can identify that a baseException
is being raised (and explain how it is better to raise a specific exception), but we can’t automatically detect which exception should be raised in this case. -
There is now a new config option to specify which rule types to display in the plugins - you can choose to any combination of refactorings, suggestions and comments.
-
Sourcery refactorings can now add imports where necessary. This means that we can suggest using standard library functions such as
contextlib.suppress
. -
aware-datetime-for-utc
suggestion -
remove-unnecessary-cast
refactoring -
replace-interpolation-with-fstring
refactoring -
swap-if-expression
refactoring -
use-contextlib-suppress
refactoring -
use-fstring-for-formatting
refactoring -
use-itertools-product
refactoring -
use-or-for-fallback
refactoring -
avoid-builtin-shadow
comment -
unwrap-iterable-construction
refactoring
Changed
path-read
will now suggest importingpathlib
if it is not already imported.- The refactoring level toggle option has been removed from VS Code and PyCharm. Which types of Sourcery rule to show can now be configured in the config file. In VS Code this can also be configured in the Sourcery settings. More configuration options for PyCharm coming soon!
Fixed
- Fix issue with string concatenation in pandas
- Fix issue where qualified names for functions were incorrect in the presence of certain keywords.
- Fix issue in
raise-from-previous-error
whereraise e from e
was suggested. - PosixPath issue causing Sourcery to crash in PyCharm
- Bug in
path-read
andaware-datetime-for-utc
that caused them to never be triggered remove-redundant-fstring
: Do not trigger if the f-string contains escaped curly braces