mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
PY-22398 False positive about missing argument for numpy.maximum.accumulate()
added skeleton for numpy.core.ufunc and numpy.core.dtype
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -17,11 +17,8 @@ package com.jetbrains.numpy.codeInsight;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.codeInsight.PyCustomMember;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.types.PyClassMembersProviderBase;
|
||||
import com.jetbrains.python.psi.types.PyClassType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
@@ -39,28 +36,13 @@ import java.util.List;
|
||||
public class NumpyClassMembersProvider extends PyClassMembersProviderBase {
|
||||
private static final String BUNCH = "sklearn.datasets.base.Bunch";
|
||||
public static final List<String> BUNCH_MEMBERS = Lists.newArrayList("target", "data", "filenames", "target_names", "DESCR");
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<PyCustomMember> getMembers(PyClassType clazz, PsiElement location, TypeEvalContext typeEvalContext) {
|
||||
if (location != null) {
|
||||
final PyClass pyClass = clazz.getPyClass();
|
||||
if (pyClass.isSubclass(PyNames.TYPES_FUNCTION_TYPE, typeEvalContext)) {
|
||||
final PsiElement element = location.getOriginalElement();
|
||||
final PsiReference reference = element.getReference();
|
||||
if (reference != null) {
|
||||
final PsiElement resolved = reference.resolve();
|
||||
if (resolved instanceof PyFunction) {
|
||||
final List<PyCustomMember> result = new ArrayList<>();
|
||||
if (NumpyUfuncs.isUFunc(((PyFunction)resolved).getName()) && NumpyDocStringTypeProvider.isInsideNumPy(resolved)) {
|
||||
for (String method : NumpyUfuncs.UFUNC_METHODS) {
|
||||
result.add(new PyCustomMember(method, resolved));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (BUNCH.equals(pyClass.getQualifiedName())) {
|
||||
if (BUNCH.equals(pyClass.getQualifiedName())) {
|
||||
final List<PyCustomMember> result = new ArrayList<>();
|
||||
for (String member : BUNCH_MEMBERS) {
|
||||
result.add(new PyCustomMember(member, NumpyDocStringTypeProvider.NDARRAY, true));
|
||||
|
||||
@@ -35,10 +35,7 @@ import com.jetbrains.python.documentation.docstrings.SectionBasedDocString.Secti
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyBuiltinCache;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveImportUtil;
|
||||
import com.jetbrains.python.psi.types.PyNoneType;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import com.jetbrains.python.psi.types.PyTypeProviderBase;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import com.jetbrains.python.psi.types.*;
|
||||
import com.jetbrains.python.toolbox.Substring;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -417,4 +414,18 @@ public class NumpyDocStringTypeProvider extends PyTypeProviderBase {
|
||||
.map(function -> getCallType(function, null, context))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PyType getReferenceType(@NotNull PsiElement referenceTarget, TypeEvalContext context, @Nullable PsiElement anchor) {
|
||||
if (referenceTarget instanceof PyFunction) {
|
||||
if (NumpyUfuncs.isUFunc(((PyFunction)referenceTarget).getName()) && isInsideNumPy(referenceTarget)) {
|
||||
// we intentionally looking here for the user stub class
|
||||
final PyClass uFuncClass = PyPsiFacade.getInstance(referenceTarget.getProject()).findClass("numpy.core.ufunc");
|
||||
if (uFuncClass != null) {
|
||||
return new PyClassTypeImpl(uFuncClass, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getReferenceType(referenceTarget, context, anchor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,16 +104,5 @@ public class NumpyUfuncs {
|
||||
UFUNC_LIST.add("trunc");
|
||||
|
||||
UFUNC_LIST.add("fabs");
|
||||
|
||||
UFUNC_METHODS.add("nin");
|
||||
UFUNC_METHODS.add("nout");
|
||||
UFUNC_METHODS.add("nargs");
|
||||
UFUNC_METHODS.add("identity");
|
||||
UFUNC_METHODS.add("ntypes");
|
||||
UFUNC_METHODS.add("accumulate");
|
||||
UFUNC_METHODS.add("reduce");
|
||||
UFUNC_METHODS.add("reduceat");
|
||||
UFUNC_METHODS.add("outer");
|
||||
UFUNC_METHODS.add("at");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user