diff --git a/python/helpers/python-skeletons/pathlib.py b/python/helpers/python-skeletons/pathlib.py index 7bcdf963f018..51e5008d80ac 100644 --- a/python/helpers/python-skeletons/pathlib.py +++ b/python/helpers/python-skeletons/pathlib.py @@ -7,7 +7,7 @@ import os class PurePath(object): def __new__(cls, *pathsegments): """ - :type pathsegments: tuple[str | bytes | os.PathLike] + :type pathsegments: str | bytes | os.PathLike :rtype: pathlib.PurePath """ return cls.__new__(*pathsegments) @@ -149,7 +149,7 @@ class PureWindowsPath(pathlib.PurePath): class Path(pathlib.PurePath): def __new__(cls, *pathsegments): """ - :type pathsegments: tuple[str | bytes | os.PathLike] + :type pathsegments: str | bytes | os.PathLike :rtype: pathlib.Path """ return cls.__new__(*pathsegments) diff --git a/python/src/com/jetbrains/python/documentation/docstrings/PyDocStringTypeProvider.java b/python/src/com/jetbrains/python/documentation/docstrings/PyDocStringTypeProvider.java index 7adf69bf74ad..0d3bacd25b1a 100644 --- a/python/src/com/jetbrains/python/documentation/docstrings/PyDocStringTypeProvider.java +++ b/python/src/com/jetbrains/python/documentation/docstrings/PyDocStringTypeProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,7 @@ import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.jetbrains.python.PyNames; import com.jetbrains.python.psi.*; -import com.jetbrains.python.psi.types.PyType; -import com.jetbrains.python.psi.types.PyTypeParser; -import com.jetbrains.python.psi.types.PyTypeProviderBase; -import com.jetbrains.python.psi.types.TypeEvalContext; +import com.jetbrains.python.psi.types.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,7 +39,17 @@ public class PyDocStringTypeProvider extends PyTypeProviderBase { if (docString != null) { final String typeText = docString.getParamType(param.getName()); if (StringUtil.isNotEmpty(typeText)) { - return parseType(func, typeText); + final Ref typeRef = parseType(func, typeText); + + if (param.isPositionalContainer()) { + return Ref.create(PyTypeUtil.toPositionalContainerType(param, typeRef.get())); + } + + if (param.isKeywordContainer()) { + return Ref.create(PyTypeUtil.toKeywordContainerType(param, typeRef.get())); + } + + return typeRef; } } return null; diff --git a/python/testData/inspections/PyTypeCheckerInspection/PositionalArguments.py b/python/testData/inspections/PyTypeCheckerInspection/PositionalArguments.py index 1d2eb2d5daf7..5487d7270ca5 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/PositionalArguments.py +++ b/python/testData/inspections/PyTypeCheckerInspection/PositionalArguments.py @@ -1,6 +1,6 @@ def foo(*args): """ - :type args: tuple[str] + :type args: str """ pass diff --git a/python/testSrc/com/jetbrains/python/PyTypeTest.java b/python/testSrc/com/jetbrains/python/PyTypeTest.java index 85e51acfef67..d079e67f688d 100644 --- a/python/testSrc/com/jetbrains/python/PyTypeTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypeTest.java @@ -1428,6 +1428,26 @@ public class PyTypeTest extends PyTestCase { "expr = raw_input()"); } + // PY-19723 + public void testPositionalArgs() { + doTest("Tuple[int, ...]", + "def foo(*args):\n" + + " \"\"\"\n" + + " :type args: int\n" + + " \"\"\"\n" + + " expr = args"); + } + + // PY-19723 + public void testKeywordArgs() { + doTest("Dict[str, int]", + "def foo(**kwargs):\n" + + " \"\"\"\n" + + " :type kwargs: int\n" + + " \"\"\"\n" + + " expr = kwargs"); + } + private static List getTypeEvalContexts(@NotNull PyExpression element) { return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(), TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());