PY-20757 Fixed: Incorrect warning about expected attribute

Make min skeletons generic.
This commit is contained in:
Semyon Proshev
2016-11-15 15:40:10 +03:00
committed by Semyon Proshev
parent a77aed6035
commit c58302f45c
4 changed files with 34 additions and 1 deletions
@@ -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.
+2 -1
View 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
@@ -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);
@@ -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());