mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-53388 Override the callable type for enum.auto() from Typeshed stubs
GitOrigin-RevId: 132e934de4da01983bebc55fcb1d3440d7053249
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3ff68f6493
commit
0fc1981b5c
+18
@@ -16,6 +16,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -124,6 +125,23 @@ public class PyStdlibTypeProvider extends PyTypeProviderBase {
|
||||
return PyTypeParser.getTypeByName(referenceTarget, "dict[str, unknown]", context);
|
||||
}
|
||||
}
|
||||
@Nullable PyType enumAutoType = getEnumAutoConstructorType(referenceTarget, context, anchor);
|
||||
if (enumAutoType != null) {
|
||||
return enumAutoType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PyType getEnumAutoConstructorType(@NotNull PsiElement target,
|
||||
@NotNull TypeEvalContext context,
|
||||
@Nullable PsiElement anchor) {
|
||||
if (target instanceof PyClass && "enum.auto".equals(((PyClass)target).getQualifiedName()) && anchor instanceof PyCallExpression) {
|
||||
PyClassLikeType classType = as(context.getType((PyTypedElement)target), PyClassLikeType.class);
|
||||
if (classType != null) {
|
||||
return new PyCallableTypeImpl(Collections.emptyList(), classType.toInstance());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,4 +74,14 @@ public class Py3ArgumentListInspectionTest extends PyInspectionTestCase {
|
||||
"\n" +
|
||||
"random.randint(1, 2)");
|
||||
}
|
||||
|
||||
// PY-53388
|
||||
public void testEnumAuto() {
|
||||
doTestByText("import enum\n" +
|
||||
"\n" +
|
||||
"class MyEnum(enum.Enum):\n" +
|
||||
" FOO = enum.auto()\n" +
|
||||
" BAR = enum.auto()\n" +
|
||||
"");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user