You can configure Sourcery to globally skip specific refactorings using the Sourcery Configuration File or directly within your code using skip comments.
Sourcery can be configured at a comment level to skip either all refactorings or to skip any refactorings within the function. These configurations are triggered with a skip comment
Skipping Entire Functions
To skip an entire function use the comment
def func(a,b): #sourcery skip if a < b: min_value = a else: min_value = b c = min_value ** 2 return c
This function would show no refactoring suggestions
Skipping Specific Refactorings
To skip specific refactorings use the comment
sourcery skip: <refactoring-id-1>, <refactoring-id-2>. You can find refactoring IDs within Sourcery's suggestion in your IDE or GitHub or a full list is available in the refactorings section of our docs.
def func(a,b): if a < b: #sourcery skip: inline-immediately-returned-variable min_value = a else: min_value = b c = min_value ** 2 return c
Will refactor to:
def func(a,b): min_value = min(a, b) c = min_value ** 2 return c
But will not suggest removing the variable
c and returning
min_value ** 2 directly.
sourcery skip comment can be made anywhere within a function