Fixed augmented assignment inspection for non-commutative operations on weak union types (PY-7605)

This commit is contained in:
Andrey Vlasovskikh
2013-02-18 13:34:23 +04:00
parent 6db030272c
commit da88f9caec
3 changed files with 13 additions and 1 deletions
@@ -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)) {
@@ -0,0 +1,7 @@
def foo(c, x, y):
if c:
z = x
else:
z = ''
y = z + y # pass
return y
@@ -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);