Skip to content

Commit 2b0b119

Browse files
authored
Merge branch 'main' into egoreliseev/Issue-106584_move_start_test
2 parents 6d835a1 + 43389e4 commit 2b0b119

21 files changed

+1439
-328
lines changed

Doc/library/stdtypes.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,11 +2014,14 @@ expression support in the :mod:`re` module).
20142014
.. versionadded:: 3.9
20152015

20162016

2017-
.. method:: str.replace(old, new[, count])
2017+
.. method:: str.replace(old, new, count=-1)
20182018

20192019
Return a copy of the string with all occurrences of substring *old* replaced by
2020-
*new*. If the optional argument *count* is given, only the first *count*
2021-
occurrences are replaced.
2020+
*new*. If *count* is given, only the first *count* occurrences are replaced.
2021+
If *count* is not specified or ``-1``, then all occurrences are replaced.
2022+
2023+
.. versionchanged:: 3.13
2024+
*count* is now supported as a keyword argument.
20222025

20232026

20242027
.. method:: str.rfind(sub[, start[, end]])

Doc/reference/datamodel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances.
16251625
:meth:`__getattr__` and :meth:`__setattr__`.) This is done both for efficiency
16261626
reasons and because otherwise :meth:`__getattr__` would have no way to access
16271627
other attributes of the instance. Note that at least for instance variables,
1628-
you can fake total control by not inserting any values in the instance attribute
1628+
you can take total control by not inserting any values in the instance attribute
16291629
dictionary (but instead inserting them in another object). See the
16301630
:meth:`__getattribute__` method below for a way to actually get total control
16311631
over attribute access.

Doc/whatsnew/3.13.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ New Features
7676
Other Language Changes
7777
======================
7878

79-
79+
* Allow the *count* argument of :meth:`str.replace` to be a keyword.
80+
(Contributed by Hugo van Kemenade in :gh:`106487`.)
8081

8182
New Modules
8283
===========

Include/internal/pycore_opcode.h

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

Include/opcode.h

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

Lib/_opcode_metadata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"LOAD_ATTR_METHOD_WITH_VALUES",
6464
"LOAD_ATTR_METHOD_NO_DICT",
6565
"LOAD_ATTR_METHOD_LAZY_DICT",
66+
"LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES",
67+
"LOAD_ATTR_NONDESCRIPTOR_NO_DICT",
6668
],
6769
"COMPARE_OP": [
6870
"COMPARE_OP_FLOAT",

Lib/test/string_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ def test_count(self):
154154
self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i))
155155
self.assertEqual(r1, r2, '%s != %s for %s' % (r1, r2, i))
156156

157+
def test_count_keyword(self):
158+
self.assertEqual('aa'.replace('a', 'b', 0), 'aa'.replace('a', 'b', count=0))
159+
self.assertEqual('aa'.replace('a', 'b', 1), 'aa'.replace('a', 'b', count=1))
160+
self.assertEqual('aa'.replace('a', 'b', 2), 'aa'.replace('a', 'b', count=2))
161+
self.assertEqual('aa'.replace('a', 'b', 3), 'aa'.replace('a', 'b', count=3))
162+
157163
def test_find(self):
158164
self.checkequal(0, 'abcdefghiabc', 'find', 'abc')
159165
self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1)

0 commit comments

Comments
 (0)