Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow str.replace's 'count' to be a keyword argument #106487

Closed
hugovk opened this issue Jul 6, 2023 · 1 comment
Closed

Allow str.replace's 'count' to be a keyword argument #106487

hugovk opened this issue Jul 6, 2023 · 1 comment
Labels
3.13 bugs and security fixes type-feature A feature request or enhancement

Comments

@hugovk
Copy link
Member

hugovk commented Jul 6, 2023

Feature or enhancement

Allow the count argument of str.replace to be a keyword to better describe its use.

Pitch

str.replace takes old and new strings as parameters, and an optional count parameter:

https://docs.python.org/3/library/stdtypes.html#str.replace

However, count cannot be a keyword argument:

>>> "aaa".replace("a", "b", 2)
'bba'
>>> "aaa".replace("a", "b", count=2)
TypeError: str.replace() takes no keyword arguments

It would be more explicit if the count parameter could also be a keyword, so there's no doubt about its meaning.

Previous discussion

Suggested by @treyhunner at https://mastodon.social/@treyhunner/110664375381530126

Linked PRs

@hugovk hugovk added type-feature A feature request or enhancement 3.13 bugs and security fixes labels Jul 6, 2023
@hugovk hugovk changed the title Allow str.replace's count to be a keyword argument Allow str.replace's 'count' to be a keyword argument Jul 6, 2023
@hugovk
Copy link
Member Author

hugovk commented Jul 10, 2023

Implemented in PR #106488 for Python 3.13, due October 2024.

https://devguide.python.org/versions/

@hugovk hugovk closed this as completed Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant