Introduce Default Else
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: introduce-default-else
Section titled “Sourcery refactoring id: introduce-default-else”Description:
Section titled “Description:”Move default state of variable into else branch
Before:
Section titled “Before:”data = ""if condition: data = dictionary["message"]After:
Section titled “After:”if condition: data = dictionary["message"]else: data = ""Explanation:
Section titled “Explanation:”A common pattern when coding is to set the state of a variable based on a
condition. Often we set a default state first, then might set it to something
different if a condition holds. In these cases Sourcery will move the default
setting into the else branch, but only if this unlocks further changes.