From ae61422dfffa53c0aea31f112de5084811e1edb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Mon, 24 Feb 2025 14:46:26 +0200 Subject: [PATCH] PY-15985: Don't suggest replacing a chained assignment with an augmented assignment GitOrigin-RevId: 6022b2b19e28b4ea424ee1022e07be328d636ad3 --- .../python/inspections/PyAugmentAssignmentInspection.java | 2 +- .../notSuggestedForChainedTarget.py | 2 ++ .../python/inspections/PyAugmentAssignmentInspectionTest.java | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 python/testData/inspections/PyAugmentAssignmentInspection/notSuggestedForChainedTarget.py diff --git a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java index 68774238ca9c..a5c8216269ad 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java +++ b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java @@ -74,7 +74,7 @@ public final class PyAugmentAssignmentInspection extends PyInspection { final PyExpression target = node.getLeftHandSideExpression(); final PyBinaryExpression value = PyUtil.as(node.getAssignedValue(), PyBinaryExpression.class); - if (target != null && value != null) { + if (target != null && value != null && node.getTargets().length == 1) { final PyExpression leftExpression = value.getLeftExpression(); final PyExpression rightExpression = PyPsiUtils.flattenParens(value.getRightExpression()); diff --git a/python/testData/inspections/PyAugmentAssignmentInspection/notSuggestedForChainedTarget.py b/python/testData/inspections/PyAugmentAssignmentInspection/notSuggestedForChainedTarget.py new file mode 100644 index 000000000000..241975434003 --- /dev/null +++ b/python/testData/inspections/PyAugmentAssignmentInspection/notSuggestedForChainedTarget.py @@ -0,0 +1,2 @@ +var = 1 +var = foo = var + 1 \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyAugmentAssignmentInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyAugmentAssignmentInspectionTest.java index 5b735e4e6a12..3bfa5cbf59bf 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyAugmentAssignmentInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyAugmentAssignmentInspectionTest.java @@ -75,6 +75,9 @@ public class PyAugmentAssignmentInspectionTest extends PyInspectionTestCase { runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest); } + // PY-15985 + public void testNotSuggestedForChainedTarget() { doTest(); } + @NotNull @Override protected Class getInspectionClass() {