Augmented Assign
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: aug-assign
Section titled “Sourcery refactoring id: aug-assign”Description:
Section titled “Description:”Replaces assignments with augmented assignments
Before:
Section titled “Before:”count = count + other_valueAfter:
Section titled “After:”count += other_valueExplanation:
Section titled “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.