mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Disable injection for Literal arguments in union/non-aliased types (PY-35235)
GitOrigin-RevId: 642984cd0aaefc499b1ec377e347e2e87936d793
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5907d1db62
commit
28daf7b20e
@@ -14,6 +14,8 @@ import com.jetbrains.python.codeInsight.functionTypeComments.PyFunctionTypeAnnot
|
||||
import com.jetbrains.python.documentation.doctest.PyDocstringLanguageDialect;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.types.PyLiteralType;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import com.jetbrains.python.psi.types.PyTypeUtil;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -92,7 +94,8 @@ public class PyTypingAnnotationInjector extends PyInjectorBase {
|
||||
if (!(parent instanceof PySubscriptionExpression)) return false;
|
||||
|
||||
final TypeEvalContext context = TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile());
|
||||
return Ref.deref(PyTypingTypeProvider.getType((PySubscriptionExpression)parent, context)) instanceof PyLiteralType;
|
||||
final PyType type = Ref.deref(PyTypingTypeProvider.getType((PySubscriptionExpression)parent, context));
|
||||
return PyTypeUtil.toStream(type).allMatch(PyLiteralType.class::isInstance);
|
||||
}
|
||||
|
||||
private static boolean isFunctionTypeComment(@NotNull PsiElement comment) {
|
||||
|
||||
@@ -1485,6 +1485,9 @@ public class PyTypingTest extends PyTestCase {
|
||||
doTestNoInjectedText("from typing import Literal\n" +
|
||||
"a: Literal[\"f<caret>oo\"]\n");
|
||||
|
||||
doTestNoInjectedText("from typing import Literal\n" +
|
||||
"a: Literal[42, \"f<caret>oo\", True]\n");
|
||||
|
||||
doTestNoInjectedText("from typing import Literal\n" +
|
||||
"MyType = Literal[42, \"f<caret>oo\", True]\n" +
|
||||
"a: MyType\n");
|
||||
|
||||
Reference in New Issue
Block a user