use of com.jetbrains.python.codeInsight.functionTypeComments.psi.PyParameterTypeList in project intellij-community by JetBrains.
the class PyTypingTypeProvider method getParameterType.
@Nullable
public Ref<PyType> getParameterType(@NotNull PyNamedParameter param, @NotNull PyFunction func, @NotNull TypeEvalContext context) {
final Ref<PyType> typeFromAnnotation = getParameterTypeFromAnnotation(param, context);
if (typeFromAnnotation != null) {
return typeFromAnnotation;
}
final Ref<PyType> typeFromTypeComment = getParameterTypeFromTypeComment(param, context);
if (typeFromTypeComment != null) {
return typeFromTypeComment;
}
final PyFunctionTypeAnnotation annotation = getFunctionTypeAnnotation(func);
if (annotation == null) {
return null;
}
final PyParameterTypeList list = annotation.getParameterTypeList();
final List<PyExpression> params = list.getParameterTypes();
if (params.size() == 1) {
final PyNoneLiteralExpression noneExpr = as(params.get(0), PyNoneLiteralExpression.class);
if (noneExpr != null && noneExpr.isEllipsis()) {
return Ref.create();
}
}
final int startOffset = omitFirstParamInTypeComment(func) ? 1 : 0;
final List<PyParameter> funcParams = Arrays.asList(func.getParameterList().getParameters());
final int i = funcParams.indexOf(param) - startOffset;
if (i >= 0 && i < params.size()) {
return getParameterTypeFromFunctionComment(params.get(i), context);
}
return null;
}
Aggregations