PY-22302 PY-23355 Don't warn about ellipsis and star expressions in function type comments

Also, UnsupportedFeatures annotator properly detects the language
level for the analyzed element. Previously, it used Python version of
the containing file for some injected fragments.
This commit is contained in:
Mikhail Golubev
2017-04-24 15:07:35 +03:00
parent 36f17034f0
commit 336dc0b210
5 changed files with 32 additions and 5 deletions
@@ -32,6 +32,7 @@ public class PyFunctionTypeAnnotationVisitorFilter implements PythonVisitorFilte
visitorClass == PyMandatoryEncodingInspection.class ||
visitorClass == PyNonAsciiCharInspection.class ||
visitorClass == PyInterpreterInspection.class ||
visitorClass == PyPep8Inspection.class);
visitorClass == PyPep8Inspection.class ||
visitorClass == PyCompatibilityInspection.class);
}
}
@@ -22,15 +22,15 @@ import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ex.ProblemDescriptorImpl;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.PyElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/**
* @author Alexey.Ivanov
@@ -42,8 +42,9 @@ public class UnsupportedFeatures extends CompatibilityVisitor {
}
@Override
public void visitPyElement(PyElement node) {
setVersionsToProcess(Arrays.asList(LanguageLevel.forElement(node)));
public synchronized void annotateElement(PsiElement psiElement, AnnotationHolder holder) {
setVersionsToProcess(Collections.singletonList(LanguageLevel.forElement(psiElement)));
super.annotateElement(psiElement, holder);
}
@Override
@@ -0,0 +1,12 @@
from typing import List
class Example:
def method(self,
lst, # type: List[str]
opt=0, # type: int
*args, # type: str
**kwargs # type: bool
):
# type: (...) -> int
"""Docstring comes after type comment."""
pass
@@ -0,0 +1,3 @@
def create_instance(self, task_config, **kwargs):
# type: (TaskConfig, **Text) -> TaskInstance
pass
@@ -219,6 +219,16 @@ public class PyCompatibilityInspectionTest extends PyTestCase {
doTest(LanguageLevel.PYTHON36);
}
// PY-22302
public void testNoWarningAboutEllipsisInFunctionTypeComments() {
doTest();
}
// PY-23355
public void testNoWarningAboutStarredExpressionsInFunctionTypeComments() {
doTest();
}
private void doTest(@NotNull LanguageLevel level) {
runWithLanguageLevel(level, this::doTest);
}