diff --git a/python/src/META-INF/python-core-common.xml b/python/src/META-INF/python-core-common.xml index 05c699c4e901..990b7ec7a818 100644 --- a/python/src/META-INF/python-core-common.xml +++ b/python/src/META-INF/python-core-common.xml @@ -711,6 +711,10 @@ + + + diff --git a/python/src/com/jetbrains/python/codeInsight/functionTypeComments/PyFunctionTypeAnnotationVisitorFilter.java b/python/src/com/jetbrains/python/codeInsight/functionTypeComments/PyFunctionTypeAnnotationVisitorFilter.java new file mode 100644 index 000000000000..9a80da979cb3 --- /dev/null +++ b/python/src/com/jetbrains/python/codeInsight/functionTypeComments/PyFunctionTypeAnnotationVisitorFilter.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jetbrains.python.codeInsight.functionTypeComments; + +import com.intellij.psi.PsiFile; +import com.jetbrains.python.inspections.*; +import org.jetbrains.annotations.NotNull; + +/** + * @author Mikhail Golubev + */ +public class PyFunctionTypeAnnotationVisitorFilter implements PythonVisitorFilter { + @Override + public boolean isSupported(@NotNull Class visitorClass, @NotNull PsiFile file) { + return !(visitorClass == PyIncorrectDocstringInspection.class || + visitorClass == PyMissingOrEmptyDocstringInspection.class || + visitorClass == PySingleQuotedDocstringInspection.class || + visitorClass == PyByteLiteralInspection.class || + visitorClass == PyMandatoryEncodingInspection.class || + visitorClass == PyNonAsciiCharInspection.class || + visitorClass == PyInterpreterInspection.class || + visitorClass == PyPep8Inspection.class); + } +} diff --git a/python/testData/inspections/InspectionsDisabledInFunctionTypeComments/test.py b/python/testData/inspections/InspectionsDisabledInFunctionTypeComments/test.py new file mode 100644 index 000000000000..96e5ed040197 --- /dev/null +++ b/python/testData/inspections/InspectionsDisabledInFunctionTypeComments/test.py @@ -0,0 +1,8 @@ +def f(x): + # type: (b'Моноцикл') -> None + pass + + +def g(): + # type: "foo" + pass diff --git a/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java b/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java index c6a3ee5e4bf5..5fd58dbc787c 100644 --- a/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java +++ b/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java @@ -351,4 +351,17 @@ public class PythonInspectionsTest extends PyTestCase { public void testPyDunderSlotsInspection() { runWithLanguageLevel(LanguageLevel.PYTHON30, () -> doHighlightingTest(PyDunderSlotsInspection.class)); } + + // PY-21645 + public void testInspectionsDisabledInFunctionTypeComments() { + myFixture.enableInspections(PyIncorrectDocstringInspection.class); + myFixture.enableInspections(PyMissingOrEmptyDocstringInspection.class); + myFixture.enableInspections(PySingleQuotedDocstringInspection.class); + myFixture.enableInspections(PyByteLiteralInspection.class); + myFixture.enableInspections(PyMandatoryEncodingInspection.class); + myFixture.enableInspections(PyNonAsciiCharInspection.class); + + myFixture.configureByFile("inspections/" + getTestName(false) + "/test.py"); + myFixture.checkHighlighting(true, false, true); + } }