Skip to content

Augmented Assign

Sourcery refactoring id: aug-assign

Description:

Replaces assignments with augmented assignments

Before:

count = count + other_value

After:

count += other_value

Explanation:

Reading the changed code is a bit shorter and clearer - we don't need to think about the count variable twice. Other operators that can be used include -=, *=, /= and **=.

The type you're assigning to has to have the appropriate operator defined, so Sourcery will only suggestion this change where it can determine the type and it is suitable. For instance numpy arrays do not support the /= operation.