Skip to content

Commit

Permalink
Treat subscript accesses as unsafe effects for autofix (#1966)
Browse files Browse the repository at this point in the history
See: #1809.
  • Loading branch information
charliermarsh authored Jan 18, 2023
1 parent 26d6414 commit 5a7d8c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions resources/test/fixtures/flake8_simplify/SIM401.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@
var = a_dict[key]
else:
var = foo()

# OK (complex default value)
if key in a_dict:
var = a_dict[key]
else:
var = a_dict["fallback"]
7 changes: 4 additions & 3 deletions src/ast/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,13 @@ pub fn contains_effect(checker: &Checker, expr: &Expr) -> bool {
// Otherwise, avoid all complex expressions.
matches!(
expr.node,
ExprKind::Call { .. }
| ExprKind::Await { .. }
ExprKind::Await { .. }
| ExprKind::Call { .. }
| ExprKind::DictComp { .. }
| ExprKind::GeneratorExp { .. }
| ExprKind::ListComp { .. }
| ExprKind::SetComp { .. }
| ExprKind::DictComp { .. }
| ExprKind::Subscript { .. }
| ExprKind::Yield { .. }
| ExprKind::YieldFrom { .. }
)
Expand Down

0 comments on commit 5a7d8c2

Please sign in to comment.