mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,4 @@ def test(c):
|
||||
f2(<warning descr="Expected type 'str', got 'int' instead">x1.count('')</warning>)
|
||||
f3(x1.count(''))
|
||||
f2(x1.strip())
|
||||
f3(<warning descr="Expected type 'int', got 'Union[str, unicode]' instead">x1.strip()</warning>)
|
||||
f3(<warning descr="Expected type 'int', got 'str' instead">x1.strip()</warning>)
|
||||
|
||||
@@ -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<TypeEvalContext> getTypeEvalContexts(@NotNull PyExpression element) {
|
||||
return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(),
|
||||
TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());
|
||||
|
||||
Reference in New Issue
Block a user