Skip to content

Commit 788da74

Browse files
authored
Merge branch 'main' into instruction-stream
2 parents e5653ee + ed55c69 commit 788da74

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

Doc/library/itertools.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,12 @@ which incur interpreter overhead.
886886
except AttributeError:
887887
# Slow path for general iterables
888888
it = islice(iterable, start, None)
889-
for i, element in enumerate(it, start):
890-
if element is value or element == value:
891-
yield i
889+
i = start - 1
890+
try:
891+
while True:
892+
yield (i := i + operator.indexOf(it, value) + 1)
893+
except ValueError:
894+
pass
892895
else:
893896
# Fast path for sequences
894897
i = start - 1

Lib/test/memory_watchdog.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@
55
# If the process crashes, reading from the /proc entry will fail with ESRCH.
66

77

8-
import os
98
import sys
109
import time
10+
from test.support import get_pagesize
1111

1212

13-
try:
14-
page_size = os.sysconf('SC_PAGESIZE')
15-
except (ValueError, AttributeError):
16-
try:
17-
page_size = os.sysconf('SC_PAGE_SIZE')
18-
except (ValueError, AttributeError):
19-
page_size = 4096
20-
2113
while True:
14+
page_size = get_pagesize()
2215
sys.stdin.seek(0)
2316
statm = sys.stdin.read()
2417
data = int(statm.split()[5])

Lib/test/test_operator.py

+3
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ def test_indexOf(self):
208208
nan = float("nan")
209209
self.assertEqual(operator.indexOf([nan, nan, 21], nan), 0)
210210
self.assertEqual(operator.indexOf([{}, 1, {}, 2], {}), 0)
211+
it = iter('leave the iterator at exactly the position after the match')
212+
self.assertEqual(operator.indexOf(it, 'a'), 2)
213+
self.assertEqual(next(it), 'v')
211214

212215
def test_invert(self):
213216
operator = self.module

Modules/_testcapi/code.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ test_code_extra(PyObject* self, PyObject *Py_UNUSED(callable))
9292
goto finally;
9393
}
9494
assert ((uintptr_t)extra == 77);
95-
95+
// Revert to initial code extra value.
96+
res = PyUnstable_Code_SetExtra(test_func_code, code_extra_index, NULL);
97+
if (res < 0) {
98+
goto finally;
99+
}
96100
result = Py_NewRef(Py_None);
97101
finally:
98102
Py_XDECREF(test_module);

0 commit comments

Comments
 (0)