PY-53388 Override the callable type for enum.auto() from Typeshed stubs

GitOrigin-RevId: 132e934de4da01983bebc55fcb1d3440d7053249
This commit is contained in:
Mikhail Golubev
2022-09-02 20:51:00 +00:00
committed by intellij-monorepo-bot
parent 3ff68f6493
commit 0fc1981b5c
2 changed files with 28 additions and 0 deletions
@@ -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" +
"");
}
}