Skip to content

Commit

Permalink
Merge branch 'main' into pymodule-add3
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Jul 10, 2023
2 parents 2da12b0 + 3e23fa7 commit 4ecdbe9
Show file tree
Hide file tree
Showing 24 changed files with 1,475 additions and 363 deletions.
9 changes: 6 additions & 3 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2014,11 +2014,14 @@ expression support in the :mod:`re` module).
.. versionadded:: 3.9


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

Return a copy of the string with all occurrences of substring *old* replaced by
*new*. If the optional argument *count* is given, only the first *count*
occurrences are replaced.
*new*. If *count* is given, only the first *count* occurrences are replaced.
If *count* is not specified or ``-1``, then all occurrences are replaced.

.. versionchanged:: 3.13
*count* is now supported as a keyword argument.


.. method:: str.rfind(sub[, start[, end]])
Expand Down
2 changes: 1 addition & 1 deletion Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances.
:meth:`__getattr__` and :meth:`__setattr__`.) This is done both for efficiency
reasons and because otherwise :meth:`__getattr__` would have no way to access
other attributes of the instance. Note that at least for instance variables,
you can fake total control by not inserting any values in the instance attribute
you can take total control by not inserting any values in the instance attribute
dictionary (but instead inserting them in another object). See the
:meth:`__getattribute__` method below for a way to actually get total control
over attribute access.
Expand Down
3 changes: 2 additions & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ New Features
Other Language Changes
======================


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

New Modules
===========
Expand Down
40 changes: 20 additions & 20 deletions Include/internal/pycore_opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 27 additions & 25 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Lib/_opcode_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"LOAD_ATTR_METHOD_WITH_VALUES",
"LOAD_ATTR_METHOD_NO_DICT",
"LOAD_ATTR_METHOD_LAZY_DICT",
"LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES",
"LOAD_ATTR_NONDESCRIPTOR_NO_DICT",
],
"COMPARE_OP": [
"COMPARE_OP_FLOAT",
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def test_count(self):
self.assertEqual(rem, 0, '%s != 0 for %s' % (rem, i))
self.assertEqual(r1, r2, '%s != %s for %s' % (r1, r2, i))

def test_count_keyword(self):
self.assertEqual('aa'.replace('a', 'b', 0), 'aa'.replace('a', 'b', count=0))
self.assertEqual('aa'.replace('a', 'b', 1), 'aa'.replace('a', 'b', count=1))
self.assertEqual('aa'.replace('a', 'b', 2), 'aa'.replace('a', 'b', count=2))
self.assertEqual('aa'.replace('a', 'b', 3), 'aa'.replace('a', 'b', count=3))

def test_find(self):
self.checkequal(0, 'abcdefghiabc', 'find', 'abc')
self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1)
Expand Down
Loading

0 comments on commit 4ecdbe9

Please sign in to comment.