mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-21244 Fix type annotations for the built-in function "map"
This commit is contained in:
@@ -202,9 +202,9 @@ def map(function, sequence, *sequence_1):
|
||||
"""Return a list of the results of applying the function to the items of
|
||||
the argument sequence(s).
|
||||
|
||||
:type function: ((T) -> V) | None
|
||||
:type function: None | (T) -> V
|
||||
:type sequence: collections.Iterable[T]
|
||||
:rtype: list[V] | bytes | unicode
|
||||
:rtype: list[V]
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@@ -195,16 +195,28 @@ def max(*args, key=None, default=None):
|
||||
pass
|
||||
|
||||
|
||||
def map(function, sequence, *sequence_1):
|
||||
"""Return a list of the results of applying the function to the items of
|
||||
the argument sequence(s).
|
||||
class map(object):
|
||||
def __init__(self, function, sequence, *sequence_1):
|
||||
"""Return an iterable of the results of applying the function to the items of
|
||||
the argument sequence(s).
|
||||
|
||||
:type function: ((T) -> V) | None
|
||||
:type sequence: collections.Iterable[T]
|
||||
:rtype: list[V] | bytes | str
|
||||
"""
|
||||
pass
|
||||
:type function: None | (T) -> V
|
||||
:type sequence: collections.Iterable[T]
|
||||
:rtype: map[T, V]
|
||||
"""
|
||||
pass
|
||||
|
||||
def __iter__(self):
|
||||
"""
|
||||
:rtype: collections.Iterator[V]
|
||||
"""
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
"""
|
||||
:rtype: V
|
||||
"""
|
||||
pass
|
||||
|
||||
def min(*args, key=None, default=None):
|
||||
"""Return the smallest item in an iterable or the smallest of two or more
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
map(<weak_warning descr="Expected type 'Optional[(Any) -> Any]' (matched generic type 'Optional[(TypeVar('T')) -> TypeVar('V')]'), got 'str' instead">'foo'</weak_warning>, <weak_warning descr="Expected type 'Iterable' (matched generic type 'Iterable[TypeVar('T')]'), got '(c: Any) -> int' instead">lambda c: 42</weak_warning>)
|
||||
@@ -1,5 +1,5 @@
|
||||
def test():
|
||||
xs = map(lambda x: x + 1, [1, 2, 3])
|
||||
print('foo' + xs[0]) # Can be a str since map returns list[V] | str | unicode
|
||||
print('foo' + <warning descr="Expected type 'Union[str, unicode]', got 'int' instead">xs[0]</warning>)
|
||||
ys = map(tuple, iter([1, 2, 3]))
|
||||
print(1 + <warning descr="Expected type 'Number', got 'Union[tuple, str, unicode]' instead">ys[0]</warning>, 'bar' + ys[1])
|
||||
print(1 + <warning descr="Expected type 'Number', got 'tuple' instead">ys[0]</warning>, 'bar' + <warning descr="Expected type 'Union[str, unicode]', got 'tuple' instead">ys[1]</warning>)
|
||||
|
||||
@@ -441,6 +441,13 @@ public class Py3TypeTest extends PyTestCase {
|
||||
"expr = float.fromhex(\"0.5\")");
|
||||
}
|
||||
|
||||
// PY-20073
|
||||
public void testMapReturnType() {
|
||||
doTest("int",
|
||||
"for x in map(lambda x: 42, 'foo'):\n" +
|
||||
" expr = x");
|
||||
}
|
||||
|
||||
private void doTest(final String expectedType, final String text) {
|
||||
myFixture.configureByText(PythonFileType.INSTANCE, text);
|
||||
final PyExpression expr = myFixture.findElementByText("expr", PyExpression.class);
|
||||
|
||||
@@ -168,4 +168,9 @@ public class Py3TypeCheckerInspectionTest extends PyTestCase {
|
||||
public void testFloatFromhex() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-20073
|
||||
public void testMapArgumentsInOppositeOrder() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,4 +341,9 @@ public class PyTypeCheckerInspectionTest extends PyTestCase {
|
||||
public void testFloatFromhex() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-20073
|
||||
public void testMapArgumentsInOppositeOrder() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user