mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-80850 Add support for Template strings as arguments of positional and keyword varargs
GitOrigin-RevId: a51c198623553ee9f0975c2b3bf7af0c86c88b7a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0b391f1a2e
commit
623f3c3482
+11
-4
@@ -17,9 +17,7 @@ import com.intellij.util.text.CharArrayUtil;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.types.PyCallableParameter;
|
||||
import com.jetbrains.python.psi.types.PyClassType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import com.jetbrains.python.psi.types.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -162,7 +160,16 @@ public final class PyFStringLikeCompletionContributor extends CompletionContribu
|
||||
}
|
||||
return ContainerUtil.all(call.multiMapArguments(PyResolveContext.defaultContext(typeEvalContext)), mapping -> {
|
||||
PyCallableParameter param = mapping.getMappedParameters().get(callArgument);
|
||||
return param != null && templateType.equals(param.getType(typeEvalContext));
|
||||
if (param == null) return false;
|
||||
PyType paramType = param.getType(typeEvalContext);
|
||||
if (param.isPositionalContainer() && paramType instanceof PyTupleType tupleType && tupleType.isHomogeneous()) {
|
||||
paramType = tupleType.getElementTypes().get(0);
|
||||
}
|
||||
else if (param.isKeywordContainer() && paramType instanceof PyCollectionType dictType &&
|
||||
PyNames.DICT.equals(dictType.getPyClass().getName())) {
|
||||
paramType = ContainerUtil.getOrElse(dictType.getElementTypes(), 1, null);
|
||||
}
|
||||
return templateType.equals(paramType);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
from string.templatelib import Template
|
||||
|
||||
def html(**chunks: Template):
|
||||
...
|
||||
|
||||
variable = 42
|
||||
html(query=t"<span>{variable<caret>}")
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
from string.templatelib import Template
|
||||
|
||||
def html(**chunks: Template):
|
||||
...
|
||||
|
||||
variable = 42
|
||||
html(query="<span>{vari<caret>")
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
from string.templatelib import Template
|
||||
|
||||
def html(*chunks: Template):
|
||||
...
|
||||
|
||||
variable = 42
|
||||
html(t"<span>{variable<caret>}")
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
from string.templatelib import Template
|
||||
|
||||
def html(*chunks: Template):
|
||||
...
|
||||
|
||||
variable = 42
|
||||
html("<span>{vari<caret>")
|
||||
@@ -516,6 +516,17 @@ public class Py3CompletionTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-80850
|
||||
public void testFStringLikeCompletionAddsTPrefixWhereTemplateStringIsExpectedAsPositionalVarargArgument() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
// PY-80850
|
||||
public void testFStringLikeCompletionAddsTPrefixWhereTemplateStringIsExpectedAsKeywordVarargArgument() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-80850
|
||||
public void testFStringLikeCompletionAddsTPrefixWhereTemplateStringIsExpectedAsAssignedValue() {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user