Merge Assignment and Augmented Assignment
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: merge-assign-and-aug-assign
Section titled “Sourcery refactoring id: merge-assign-and-aug-assign”Description:
Section titled “Description:”Replaces an assignment and an augmented assignment with a single assignment.
Before:
Section titled “Before:”other_value = 33number = 42number += other_valueAfter:
Section titled “After:”other_value = 33number = 42 + other_valueExplanation:
Section titled “Explanation:”When we mutate a variable multiple times without reading or writing its value in between, it’s more readable and more efficient to change its value only once. This way, it’s clearer which values this variable can have at various points.
This refactoring works with all 4 augmented assignment operators:
+=-=*=/=