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:
Semyon Proshev
2016-11-25 19:02:43 +03:00
parent 421655e180
commit 45ec95d939
3 changed files with 96 additions and 26 deletions
@@ -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());