diff --git a/python/helpers/StdlibTypes.properties b/python/helpers/StdlibTypes.properties index 7cffa26fb987..657e8f025db4 100644 --- a/python/helpers/StdlibTypes.properties +++ b/python/helpers/StdlibTypes.properties @@ -1,184 +1,6 @@ # Python stdlib -## 8.3. collections - -collections.Iterator.__init__ = \ - :rtype: collections.Iterator of T \n\ - -collections.Iterator.next = \ - :rtype: T \n\ - - -## 9.2 math - -math.acos = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.acosh = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.asin = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.asinh = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.atan = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.atan2 = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.atanh = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.ceil = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.copysign = \ - :type x: float or numbers.Real \n\ - :type y: float or numbers.Real \n\ - :rtype: float \n\ - -math.cos = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.cosh = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.degrees = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.erf = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.erfc = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.exp = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.expm1 = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.fabs = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.factorial = \ - :type x: int or long \n\ - :rtype: int \n\ - -math.floor = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.fmod = \ - :type x: float or numbers.Real \n\ - :type y: float or numbers.Real \n\ - :rtype: float \n\ - -math.frexp = \ - :type x: float or numbers.Real \n\ - :rtype: (float, int) \n\ - -math.fsum = \ - :type iterable: collections.Iterable of float \n\ - :rtype: float \n\ - -math.gamma = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.hypot = \ - :type x: float or numbers.Real \n\ - :type y: float or numbers.Real \n\ - :rtype: float \n\ - -math.isinf = \ - :type x: float or numbers.Real \n\ - :rtype: bool \n\ - -math.isnan = \ - :type x: float or numbers.Real \n\ - :rtype: bool \n\ - -math.ldexp = \ - :type x: float or numbers.Real \n\ - :type y: float or numbers.Real \n\ - :rtype: float \n\ - -math.lgamma = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.log = \ - :type x: float or numbers.Real \n\ - :type base: float or numbers.Real \n\ - :rtype: float \n\ - -math.log10 = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.log1p = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.modf = \ - :type x: float or numbers.Real \n\ - :rtype: (float, float) \n\ - -math.pow = \ - :type x: float or numbers.Real \n\ - :type y: float or numbers.Real \n\ - :rtype: float \n\ - -math.radians = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.sin = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.sinh = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.sqrt = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.tan = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.tanh = \ - :type x: float or numbers.Real \n\ - :rtype: float \n\ - -math.trunc = \ - :type x: float or numbers.Real \n\ - :rtype: int \n\ - - ## 9.4. decimal decimal.Decimal.as_tuple = \ diff --git a/python/src/com/jetbrains/python/psi/types/PyTypeParser.java b/python/src/com/jetbrains/python/psi/types/PyTypeParser.java index 82da9b4a9713..e064ac31b83f 100644 --- a/python/src/com/jetbrains/python/psi/types/PyTypeParser.java +++ b/python/src/com/jetbrains/python/psi/types/PyTypeParser.java @@ -24,6 +24,7 @@ import com.intellij.psi.PsiFile; import com.intellij.util.Function; import com.intellij.util.containers.hash.HashMap; import com.jetbrains.python.PyNames; +import com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsUtil; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.impl.PyBuiltinCache; import com.intellij.psi.util.QualifiedName; @@ -522,12 +523,23 @@ public class PyTypeParser { private ParseResult fromClassNameIndex(@NotNull Token token) { final Collection classes = PyClassNameIndex.find(token.getText().toString(), myAnchor.getProject(), true); if (classes.size() == 1) { - final PyClassTypeImpl type = new PyClassTypeImpl(classes.iterator().next(), false); - type.assertValid("PyClassNameIndex.find().iterator().next()"); - return new ParseResult(type, token.getRange()); + return parseResultFromClass(token, classes.iterator().next()); + } + for (PyClass cls : classes) { + final PsiFile file = cls.getContainingFile(); + if (file != null && !PyUserSkeletonsUtil.isUnderUserSkeletonsDirectory(file)) { + return parseResultFromClass(token, cls); + } } return null; } + + @NotNull + private static ParseResult parseResultFromClass(@NotNull Token token, @NotNull PyClass cls) { + final PyClassTypeImpl type = new PyClassTypeImpl(cls, false); + type.assertValid("PyClassNameIndex.find().iterator()"); + return new ParseResult(type, token.getRange()); + } } private static FunctionalParser, PyElementType> op(@Nullable String text) { diff --git a/python/testSrc/com/jetbrains/python/PyTypeParserTest.java b/python/testSrc/com/jetbrains/python/PyTypeParserTest.java index aa5acf1efb3c..30dc43404a3c 100644 --- a/python/testSrc/com/jetbrains/python/PyTypeParserTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypeParserTest.java @@ -15,6 +15,8 @@ */ package com.jetbrains.python; +import com.intellij.psi.PsiFile; +import com.jetbrains.python.documentation.PythonDocumentationProvider; import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.types.*; @@ -34,7 +36,7 @@ public class PyTypeParserTest extends PyTestCase { private static void assertClassType(PyType type, final String name) { assertNotNull(type); - assertEquals(name, ((PyClassType) type).getPyClass().getName()); + assertEquals(name, ((PyClassType)type).getPyClass().getName()); } public void testTupleType() { @@ -276,4 +278,21 @@ public class PyTypeParserTest extends PyTestCase { assertNotNull(parameterTypes); assertEquals(0, parameterTypes.size()); } + + public void testQualifiedUserSkeletonsClass() { + doTest("Iterator[int]", "collections.Iterator[int]"); + } + + public void testUnqualifiedUserSkeletonsClass() { + doTest("Iterator[int]", "Iterator[int]"); + } + + private void doTest(final String expectedType, final String text) { + myFixture.configureByFile("typeParser/typeParser.py"); + final PsiFile file = myFixture.getFile(); + final PyType type = PyTypeParser.getTypeByName(file, text); + TypeEvalContext context = TypeEvalContext.userInitiated(file).withTracing(); + final String actualType = PythonDocumentationProvider.getTypeName(type, context); + assertEquals(expectedType, actualType); + } } diff --git a/python/testSrc/com/jetbrains/python/PyTypeTest.java b/python/testSrc/com/jetbrains/python/PyTypeTest.java index 7969d395dd89..cfa29662898a 100644 --- a/python/testSrc/com/jetbrains/python/PyTypeTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypeTest.java @@ -799,6 +799,12 @@ public class PyTypeTest extends PyTestCase { "expr = c.foo\n"); } + public void testIterNext() { + doTest("int", + "xs = [1, 2, 3]\n" + + "expr = iter(xs).next()\n"); + } + private static TypeEvalContext getTypeEvalContext(@NotNull PyExpression element) { return TypeEvalContext.userInitiated(element.getContainingFile()).withTracing(); }