Use-Or-For-Fallback
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 rule id: use-or-for-fallback
Section titled “Sourcery rule id: use-or-for-fallback”Description
Section titled “Description”Use or for providing a fallback value
Before
Section titled “Before”pattern = provided_patternif not pattern: pattern = pattern_from_configpattern = provided_pattern or pattern_from_configExplanation
Section titled “Explanation”Thanks to the flexibility of Python’s or operator, you can use a single
assignment statement, even if a variable can retrieve its value from various
sources. This is shorter and easier to read than using multiple assignments with
if not conditions.