From e2f46537fdd6a8842aa595db4221e89a9956b337 Mon Sep 17 00:00:00 2001 From: Harutaka Kawamura Date: Sun, 4 Sep 2022 11:56:55 +0900 Subject: [PATCH] Fix false positive for `IfTuple` (#96) --- resources/test/fixtures/F634.py | 2 ++ src/check_ast.rs | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/resources/test/fixtures/F634.py b/resources/test/fixtures/F634.py index 501a7f8ad2..f23ac85a36 100644 --- a/resources/test/fixtures/F634.py +++ b/resources/test/fixtures/F634.py @@ -6,3 +6,5 @@ for _ in range(5): pass elif (3, 4): pass + elif (): + pass diff --git a/src/check_ast.rs b/src/check_ast.rs index ec8efab33c..a5794c930b 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -241,11 +241,13 @@ impl Visitor for Checker<'_> { } StmtKind::If { test, .. } => { if self.settings.select.contains(CheckKind::IfTuple.code()) { - if let ExprKind::Tuple { .. } = test.node { - self.checks.push(Check { - kind: CheckKind::IfTuple, - location: stmt.location, - }); + if let ExprKind::Tuple { elts, .. } = &test.node { + if !elts.is_empty() { + self.checks.push(Check { + kind: CheckKind::IfTuple, + location: stmt.location, + }); + } } } }