PY-19723 Fixed: Type hinting of arbitrary argument lists and default argument values

Update PyTypingTypeProvider to correctly handle `args: T1` and `kwargs: T2`, and wrap their types to `Tuple[T1, ...]` and `Dict[str, T2]`.
This commit is contained in:
Semyon Proshev
2016-11-25 19:02:41 +03:00
parent 271e4264eb
commit 5e214c4b4a
3 changed files with 106 additions and 32 deletions
@@ -31,7 +31,6 @@ import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.PyExpression;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.TypeEvalContext;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -736,6 +735,34 @@ public class PyTypingTest extends PyTestCase {
"expr = (w, x, y, z)\n");
}
// PY-19723
public void testAnnotatedPositionalArgs() {
doTest("Tuple[str, ...]",
"def foo(*args: str):\n" +
" expr = args\n");
}
// PY-19723
public void testAnnotatedKeywordArgs() {
doTest("Dict[str, int]",
"def foo(**kwargs: int):\n" +
" expr = kwargs\n");
}
// PY-19723
public void testTypeCommentedPositionalArgs() {
doTest("Tuple[str, ...]",
"def foo(*args # type: str\n):\n" +
" expr = args\n");
}
// PY-19723
public void testTypeCommentedKeywordArgs() {
doTest("Dict[str, int]",
"def foo(**kwargs # type: int\n):\n" +
" expr = kwargs\n");
}
private void doTestNoInjectedText(@NotNull String text) {
myFixture.configureByText(PythonFileType.INSTANCE, text);
final InjectedLanguageManager languageManager = InjectedLanguageManager.getInstance(myFixture.getProject());