id: prefer-dict-get
language: python
severity: hint
message: Use `$D.get($K, $DEFAULT)` instead of a conditional key lookup.
note: |
`d.get(key, default)` is more concise and idiomatic than checking
membership and indexing separately. This rule matches the ternary
expression pattern `d[k] if k in d else default`.
rule:
pattern: "$D[$K] if $K in $D else $DEFAULT"
fix: $D.get($K, $DEFAULT)
files:
- "**/*.py"
- "!tests/**"
- "!**/test_*.py"
- "!**/*_test.py"