PY-20757 Fixed: Incorrect warning about expected attribute
authorSemyon Proshev <semyon.proshev@jetbrains.com>
Thu, 10 Nov 2016 15:14:00 +0000 (18:14 +0300)
committerSemyon Proshev <Semyon.Proshev@jetbrains.com>
Tue, 15 Nov 2016 12:40:10 +0000 (15:40 +0300)
Make min skeletons generic.

python/helpers/python-skeletons/__builtin__.py
python/helpers/python-skeletons/builtins.py
python/testSrc/com/jetbrains/python/Py3TypeTest.java
python/testSrc/com/jetbrains/python/PyTypeTest.java

index b592718b9ff134f6478775991e74832ede58d42e..5276f485f2b34af4016bd5b64d288dfb8b2e5a5c 100644 (file)
@@ -209,6 +209,16 @@ def map(function, sequence, *sequence_1):
     pass
 
 
+def min(*args, key=None, default=None):
+    """Return the smallest item in an iterable or the smallest of two or more
+    arguments.
+
+    :type args: tuple[T]
+    :rtype: T
+    """
+    pass
+
+
 def next(iterator, default=None):
     """Return the next item from the iterator.
 
index 036fc2dc6ba7f05898162bee9907c37335a9cfa4..07a50074679a937001b89b2d89a8f603a9ab7516 100644 (file)
@@ -225,7 +225,8 @@ def min(*args, key=None, default=None):
     """Return the smallest item in an iterable or the smallest of two or more
     arguments.
 
-    :rtype: object | unknown
+    :type args: tuple[T]
+    :rtype: T
     """
     pass
 
index 46bc84cf6ef7fc55463eeabbc3a600b8bc77c7c8..c8cb9818b708e49106f2aebac0342453f9fa3821 100644 (file)
@@ -448,6 +448,17 @@ public class Py3TypeTest extends PyTestCase {
            "    expr = x");
   }
 
+  // PY-20757
+  public void testMinElseNone() {
+    doTest("Union[None, Any]",
+           "def get_value(v):\n" +
+           "    if v:\n" +
+           "        return min(v)\n" +
+           "    else:\n" +
+           "        return None\n" +
+           "expr = get_value([])");
+  }
+
   private void doTest(final String expectedType, final String text) {
     myFixture.configureByText(PythonFileType.INSTANCE, text);
     final PyExpression expr = myFixture.findElementByText("expr", PyExpression.class);
index 29ba56c4cfbbe8f4b9dcc9d22fde73fac3982fad..259eee353529772ecaafad0ba16e67ab2987f534 100644 (file)
@@ -1398,6 +1398,17 @@ public class PyTypeTest extends PyTestCase {
            "expr = float.fromhex(\"0.5\")");
   }
 
+  // PY-20757
+  public void testMinOrNone() {
+    doTest("Union[None, Any]",
+           "def get_value(v):\n" +
+           "    if v:\n" +
+           "        return min(v)\n" +
+           "    else:\n" +
+           "        return None\n" +
+           "expr = get_value([])");
+  }
+
   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());