Skip to content

Commit 72f2d44

Browse files
authored
Merge branch 'main' into doc-ob-mutex-warning
2 parents 8c202f0 + 432ddd9 commit 72f2d44

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

Doc/library/stdtypes.rst

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,18 @@ expression support in the :mod:`re` module).
21802180
Return ``True`` if all characters in the string are alphanumeric and there is at
21812181
least one character, ``False`` otherwise. A character ``c`` is alphanumeric if one
21822182
of the following returns ``True``: ``c.isalpha()``, ``c.isdecimal()``,
2183-
``c.isdigit()``, or ``c.isnumeric()``.
2183+
``c.isdigit()``, or ``c.isnumeric()``. For example::
2184+
2185+
.. doctest::
2186+
2187+
>>> 'abc123'.isalnum()
2188+
True
2189+
>>> 'abc123!@#'.isalnum()
2190+
False
2191+
>>> ''.isalnum()
2192+
False
2193+
>>> ' '.isalnum()
2194+
False
21842195

21852196

21862197
.. method:: str.isalpha()
@@ -2472,6 +2483,19 @@ expression support in the :mod:`re` module).
24722483
after the separator. If the separator is not found, return a 3-tuple containing
24732484
the string itself, followed by two empty strings.
24742485

2486+
For example:
2487+
2488+
.. doctest::
2489+
2490+
>>> 'Monty Python'.partition(' ')
2491+
('Monty', ' ', 'Python')
2492+
>>> "Monty Python's Flying Circus".partition(' ')
2493+
('Monty', ' ', "Python's Flying Circus")
2494+
>>> 'Monty Python'.partition('-')
2495+
('Monty Python', '', '')
2496+
2497+
See also :meth:`rpartition`.
2498+
24752499

24762500
.. method:: str.removeprefix(prefix, /)
24772501

Lib/test/test_capi/test_opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,23 @@ def f(n):
19861986
self.assertNotIn("_GUARD_NOS_TUPLE", uops)
19871987
self.assertIn("_BINARY_OP_SUBSCR_TUPLE_INT", uops)
19881988

1989+
def test_remove_guard_for_known_type_slice(self):
1990+
def f(n):
1991+
x = 0
1992+
for _ in range(n):
1993+
l = [1, 2, 3]
1994+
slice_obj = slice(0, 1)
1995+
x += l[slice_obj][0] # guarded
1996+
x += l[slice_obj][0] # unguarded
1997+
return x
1998+
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
1999+
self.assertEqual(res, TIER2_THRESHOLD * 2)
2000+
uops = get_opnames(ex)
2001+
2002+
count = count_ops(ex, "_GUARD_TOS_SLICE")
2003+
self.assertEqual(count, 1)
2004+
self.assertIn("_BINARY_OP_SUBSCR_LIST_INT", uops)
2005+
19892006
def test_remove_guard_for_tuple_bounds_check(self):
19902007
def f(n):
19912008
x = 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimise ``_GUARD_TOS_SLICE`` in the JIT.

Python/optimizer_bytecodes.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,13 @@ dummy_func(void) {
13741374
}
13751375
}
13761376

1377+
op(_GUARD_TOS_SLICE, (tos -- tos)) {
1378+
if (sym_matches_type(tos, &PySlice_Type)) {
1379+
ADD_OP(_NOP, 0, 0);
1380+
}
1381+
sym_set_type(tos, &PySlice_Type);
1382+
}
1383+
13771384
op(_GUARD_NOS_NULL, (null, unused -- null, unused)) {
13781385
if (sym_is_null(null)) {
13791386
ADD_OP(_NOP, 0, 0);

Python/optimizer_cases.c.h

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)