diff --git a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyStringFormatInspection.java b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyStringFormatInspection.java index 4dcb4223b1fb..631257e7371b 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyStringFormatInspection.java +++ b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyStringFormatInspection.java @@ -142,7 +142,9 @@ public final class PyStringFormatInspection extends PyInspection { } else { final PyTupleType tupleType = (PyTupleType)myTypeEvalContext.getType(rightExpression); - assert tupleType != null; + if (tupleType == null) { + return -1; + } matchEntireTupleTypes(problemTarget, tupleType); return tupleType.getElementCount(); } diff --git a/python/testData/inspections/PyStringFormatInspection/TupleFormat.py b/python/testData/inspections/PyStringFormatInspection/TupleFormat.py new file mode 100644 index 000000000000..908c7e3f71a1 --- /dev/null +++ b/python/testData/inspections/PyStringFormatInspection/TupleFormat.py @@ -0,0 +1,2 @@ +a = ("b", "c") +d = "%s" % a \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java b/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java index c4bfbfc80dba..44972d704d6a 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java +++ b/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java @@ -119,6 +119,10 @@ public abstract class PyTestCase extends UsefulTestCase { protected void assertSdkRootsNotParsed(@NotNull PsiFile currentFile) { final Sdk testSdk = PythonSdkUtil.findPythonSdk(currentFile); + if (testSdk == null) { + LOG.warn("testSdk is null. assertSdkRootsNotParsed is skipped"); + return; + } for (VirtualFile root : testSdk.getRootProvider().getFiles(OrderRootType.CLASSES)) { assertRootNotParsed(currentFile, root, null); } diff --git a/python/testSrc/com/jetbrains/python/inspections/PyStringFormatNoSDKInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyStringFormatNoSDKInspectionTest.java new file mode 100644 index 000000000000..6a6da3d6c745 --- /dev/null +++ b/python/testSrc/com/jetbrains/python/inspections/PyStringFormatNoSDKInspectionTest.java @@ -0,0 +1,31 @@ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.jetbrains.python.inspections; + +import com.intellij.testFramework.LightProjectDescriptor; +import com.jetbrains.python.fixtures.PyInspectionTestCase; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PyStringFormatNoSDKInspectionTest extends PyInspectionTestCase { + + @Override + protected @Nullable LightProjectDescriptor getProjectDescriptor() { + return LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR; + } + + // PY-80147 + public void testTupleFormat() { + doTest(); + } + + @NotNull + @Override + protected Class getInspectionClass() { + return PyStringFormatInspection.class; + } + + @Override + protected boolean isLowerCaseTestFile() { + return false; + } +}