Switch
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: switch
Section titled “Sourcery refactoring id: switch”Description:
Section titled “Description:”Simplify conditionals into a form more like a switch statement
Before:
Section titled “Before:”if item.a == 1: q += 2elif item.a == 2: q += 2elif item.a == 4: q = 0After:
Section titled “After:”if item.a in [1, 2]: q += 2elif item.a == 4: q = 0Explanation:
Section titled “Explanation:”This refactoring examines complex conditionals where a variable is being compared to various different values, and tries to put them into the simplest form possible, eliminating duplicated blocks.