mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-19723 Fixed: Type hinting of arbitrary argument lists and default argument values
Update PyTypeChecker to substitute type vars with types of positional and keyword args (incl. heterogeneous ones)
This commit is contained in:
@@ -1456,6 +1456,54 @@ public class PyTypeTest extends PyTestCase {
|
||||
" pass");
|
||||
}
|
||||
|
||||
// PY-19723
|
||||
public void testTypeVarSubstitutionInPositionalArgs() {
|
||||
doTest("int",
|
||||
"def foo(*args):" +
|
||||
" \"\"\"\n" +
|
||||
" :type args: T\n" +
|
||||
" :rtype: T\n" +
|
||||
" \"\"\"\n" +
|
||||
" pass\n" +
|
||||
"expr = foo(1)");
|
||||
}
|
||||
|
||||
// PY-19723
|
||||
public void testTypeVarSubstitutionInHeterogeneousPositionalArgs() {
|
||||
doTest("Union[int, str]",
|
||||
"def foo(*args):" +
|
||||
" \"\"\"\n" +
|
||||
" :type args: T\n" +
|
||||
" :rtype: T\n" +
|
||||
" \"\"\"\n" +
|
||||
" pass\n" +
|
||||
"expr = foo(1, \"2\")");
|
||||
}
|
||||
|
||||
// PY-19723
|
||||
public void testTypeVarSubstitutionInKeywordArgs() {
|
||||
doTest("int",
|
||||
"def foo(**kwargs):" +
|
||||
" \"\"\"\n" +
|
||||
" :type kwargs: T\n" +
|
||||
" :rtype: T\n" +
|
||||
" \"\"\"\n" +
|
||||
" pass\n" +
|
||||
"expr = foo(a=1)");
|
||||
}
|
||||
|
||||
// PY-19723
|
||||
public void testTypeVarSubstitutionInHeterogeneousKeywordArgs() {
|
||||
doTest("Union[int, str]",
|
||||
"def foo(**kwargs):" +
|
||||
" \"\"\"\n" +
|
||||
" :type kwargs: T\n" +
|
||||
" :rtype: T\n" +
|
||||
" \"\"\"\n" +
|
||||
" pass\n" +
|
||||
"expr = foo(a=1, b=\"2\")");
|
||||
}
|
||||
|
||||
private static List<TypeEvalContext> getTypeEvalContexts(@NotNull PyExpression element) {
|
||||
return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(),
|
||||
TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());
|
||||
|
||||
Reference in New Issue
Block a user