From 7a23d509b8746086ca9199c72eee21ba546afc3e Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Tue, 18 Apr 2017 15:45:09 +0300 Subject: [PATCH] PY-22919 Fixed: max() function transmits argument type to return type PY-23634 Fixed: min() from comprehension with unknown items type return list Primarily these issues were fixed by PY-22808-related commits. In these change inferred call type is more precise. PyiTypeProvider doesn't take into account overloads that have unmapped args or params. --- .../jetbrains/python/pyi/PyiTypeProvider.java | 6 ++--- .../UnionReturnTypes.py | 2 +- .../com/jetbrains/python/PyTypeTest.java | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/pyi/PyiTypeProvider.java b/python/src/com/jetbrains/python/pyi/PyiTypeProvider.java index f6c2df5f8923..c66bd88780e7 100644 --- a/python/src/com/jetbrains/python/pyi/PyiTypeProvider.java +++ b/python/src/com/jetbrains/python/pyi/PyiTypeProvider.java @@ -29,8 +29,6 @@ import org.jetbrains.annotations.Nullable; import java.util.*; -import static com.jetbrains.python.psi.PyUtil.as; - /** * @author vlan */ @@ -212,10 +210,10 @@ public class PyiTypeProvider extends PyTypeProviderBase { final PyCallExpressionHelper.ArgumentMappingResults mapping = PyCallExpressionHelper.mapArguments(callSite, function, parameters, context); - final PyCallExpression callExpr = as(callSite, PyCallExpression.class); - if (callExpr != null && callExpr.getArguments().length != mapping.getMappedParameters().size()) { + if (!mapping.getUnmappedArguments().isEmpty() || !mapping.getUnmappedParameters().isEmpty()) { return null; } + return mapping; } } diff --git a/python/testData/inspections/PyTypeCheckerInspection/UnionReturnTypes.py b/python/testData/inspections/PyTypeCheckerInspection/UnionReturnTypes.py index d1dccf7e5b61..30e2ab7ddda1 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/UnionReturnTypes.py +++ b/python/testData/inspections/PyTypeCheckerInspection/UnionReturnTypes.py @@ -22,4 +22,4 @@ def test(c): f2(x1.count('')) f3(x1.count('')) f2(x1.strip()) - f3(x1.strip()) + f3(x1.strip()) diff --git a/python/testSrc/com/jetbrains/python/PyTypeTest.java b/python/testSrc/com/jetbrains/python/PyTypeTest.java index f75e723a94d9..82fa720aaf9c 100644 --- a/python/testSrc/com/jetbrains/python/PyTypeTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypeTest.java @@ -1677,6 +1677,32 @@ public class PyTypeTest extends PyTestCase { " return get_class()"); } + // PY-22919 + public void testMaxListKnownElements() { + doTest("int", + "expr = max([1, 2, 3])"); + } + + // PY-22919 + public void testMaxListUnknownElements() { + doTest("Any", + "l = []\n" + + "expr = max(l)"); + } + + // PY-23634 + public void testMinListKnownElements() { + doTest("int", + "expr = min([1, 2, 3])"); + } + + // PY-23634 + public void testMinListUnknownElements() { + doTest("Any", + "l = []\n" + + "expr = min(l)"); + } + private static List getTypeEvalContexts(@NotNull PyExpression element) { return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(), TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());