Reduce unstubbing in PyDataclassesTypeProvider (PY-27398)

This commit is contained in:
Semyon Proshev
2018-01-22 22:52:07 +03:00
parent 29f25b8beb
commit 3c888b95f3
4 changed files with 10 additions and 20 deletions
@@ -62,12 +62,8 @@ class PyDataclassesTypeProvider : PyTypeProviderBase() {
val parameters = ArrayList<PyCallableParameter>()
cls.processClassLevelDeclarations { element, _ ->
if (element is PyTargetExpression && element.annotationValue != null) {
val annotation = element.annotation
if (annotation != null && !PyTypingTypeProvider.isClassVarAnnotation(annotation, context)) {
parameters.add(PyCallableParameterImpl.nonPsi(element.name, getTypeForParameter(element, context), element.findAssignedValue()))
}
if (element is PyTargetExpression && !PyTypingTypeProvider.isClassVar(element, context)) {
parameters.add(PyCallableParameterImpl.nonPsi(element.name, getTypeForParameter(element, context), element.findAssignedValue()))
}
true
@@ -8,7 +8,6 @@ import com.google.common.collect.Sets;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.ResolveResult;
import com.intellij.psi.impl.source.resolve.FileContextUtil;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
@@ -1245,15 +1244,15 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
return Ref.create(PyTypeParser.getTypeByName(call, type, context));
}
public static boolean isClassVarAnnotation(@NotNull PyAnnotation annotation, @NotNull TypeEvalContext context) {
final PyExpression value = annotation.getValue();
public static boolean isClassVar(@NotNull PyAnnotationOwner annotationOwner, @NotNull TypeEvalContext context) {
final PyExpression annotationValue = getAnnotationValue(annotationOwner, context);
if (value instanceof PySubscriptionExpression) {
final PyExpression operand = ((PySubscriptionExpression)value).getOperand();
if (annotationValue instanceof PySubscriptionExpression) {
final PyExpression operand = ((PySubscriptionExpression)annotationValue).getOperand();
return operand instanceof PyReferenceExpression && resolveToQualifiedNames(operand, context).contains(CLASSVAR);
}
else if (value instanceof PyReferenceExpression) {
return resolveToQualifiedNames(value, context).contains(CLASSVAR);
else if (annotationValue instanceof PyReferenceExpression) {
return resolveToQualifiedNames(annotationValue, context).contains(CLASSVAR);
}
return false;
@@ -54,13 +54,9 @@ class PyDataclassInspection : PyInspection() {
val initVars = mutableListOf<PyTargetExpression>()
node.processClassLevelDeclarations { element, _ ->
if (element is PyTargetExpression && element.annotationValue != null) {
val annotation = element.annotation
if (annotation != null && !PyTypingTypeProvider.isClassVarAnnotation(annotation, myTypeEvalContext)) {
if (element is PyTargetExpression && !PyTypingTypeProvider.isClassVar(element, myTypeEvalContext)) {
processDefaultFieldValue(element)
processAsInitVar(element, postInit)?.let { initVars.add(it) }
}
}
true
@@ -75,8 +75,7 @@ class PyNamedTupleInspection : PyInspection() {
override fun execute(element: PsiElement, state: ResolveState): Boolean {
if (element is PyTargetExpression) {
val annotation = element.annotation
if (annotation != null && PyTypingTypeProvider.isClassVarAnnotation(annotation, context)) {
if (PyTypingTypeProvider.isClassVar(element, context)) {
return true
}