Collection Into Set
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: collection-into-set
Section titled “Sourcery refactoring id: collection-into-set”Description:
Section titled “Description:”Use set when checking membership of a collection of literals
Before:
Section titled “Before:”if currency in ["EUR", "USD"]: take_payment()After:
Section titled “After:”if currency in {"EUR", "USD"}: take_payment()Explanation:
Section titled “Explanation:”When checking if a variable is one of a collection of literals it is both more
natural and more performant to use a set rather than a list or tuple to
define that collection. Note that this can only be done where Sourcery can
ascertain that the value being checked is of a hashable type.