From da88f9caec5b0d0288f15b6036652a388147872a Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 18 Feb 2013 13:34:23 +0400 Subject: [PATCH] Fixed augmented assignment inspection for non-commutative operations on weak union types (PY-7605) --- .../python/inspections/PyAugmentAssignmentInspection.java | 2 +- .../PyAugmentAssignmentInspection/strOrUnknownFirstArg.py | 7 +++++++ .../inspections/PyAugmentAssignmentInspectionTest.java | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 python/testData/inspections/PyAugmentAssignmentInspection/strOrUnknownFirstArg.py diff --git a/python/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java b/python/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java index 5503bae70e43..5762fa6f4b4a 100644 --- a/python/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyAugmentAssignmentInspection.java @@ -74,7 +74,7 @@ public class PyAugmentAssignmentInspection extends PyInspection { if ((operations.contains(op) && !changedParts) || (changedParts && commutativeOperations.contains(op))) { if (leftExpression instanceof PyReferenceExpression || leftExpression instanceof PySubscriptionExpression) { final PyType type = myTypeEvalContext.getType(rightExpression); - if (type != null) { + if (type != null && !PyTypeChecker.isUnknown(type)) { final PyBuiltinCache cache = PyBuiltinCache.getInstance(rightExpression); final LanguageLevel languageLevel = LanguageLevel.forElement(rightExpression); if (isNumeric(type, cache) || (isString(type, cache, languageLevel) && !changedParts)) { diff --git a/python/testData/inspections/PyAugmentAssignmentInspection/strOrUnknownFirstArg.py b/python/testData/inspections/PyAugmentAssignmentInspection/strOrUnknownFirstArg.py new file mode 100644 index 000000000000..f876b7e334f2 --- /dev/null +++ b/python/testData/inspections/PyAugmentAssignmentInspection/strOrUnknownFirstArg.py @@ -0,0 +1,7 @@ +def foo(c, x, y): + if c: + z = x + else: + z = '' + y = z + y # pass + return y diff --git a/python/testSrc/com/jetbrains/python/inspections/PyAugmentAssignmentInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyAugmentAssignmentInspectionTest.java index 3ad5432d4543..fc87de23f50f 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyAugmentAssignmentInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyAugmentAssignmentInspectionTest.java @@ -47,6 +47,11 @@ public class PyAugmentAssignmentInspectionTest extends PyTestCase { doTest(); } + // PY-7605 + public void testStrOrUnknownFirstArg() { + doTest(); + } + private void doTest() { myFixture.configureByFile("inspections/PyAugmentAssignmentInspection/" + getTestName(true) + ".py"); myFixture.enableInspections(PyAugmentAssignmentInspection.class);