Skip to content

gh-140911: Ensure that UserString.rindex(), UserString.index() accept UserString as sub argument. - #140945

Merged
serhiy-storchaka merged 5 commits into
python:mainfrom
XChaitanyaX:pr_140911
Nov 25, 2025
Merged

gh-140911: Ensure that UserString.rindex(), UserString.index() accept UserString as sub argument.#140945
serhiy-storchaka merged 5 commits into
python:mainfrom
XChaitanyaX:pr_140911

Conversation

@XChaitanyaX

@XChaitanyaXXChaitanyaX commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Add isinstance check to both methods index(), rindex()

@XChaitanyaXXChaitanyaX changed the title gh-140911: Make sure that UserString.rindex(), UserString.index() accept UserString as sub argument.gh-140911: Ensure that UserString.rindex(), UserString.index() accept UserString as sub argument.Nov 3, 2025

@PredictiveManishPredictiveManish left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Closes: in description! so that it directly links to main issue (like below)

Add isinstance check to both methods index(), rindex()

Closes: #140911

@XChaitanyaX

Copy link
Copy Markdown
ContributorAuthor

@serhiy-storchaka can you please review this...

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add tests?

Look at test_find, test_rfind and test_count methods in Lib/test/string_tests.py and add similar double loops in test_index and test_rindex.

Comment threadLib/test/string_tests.py Outdated
Comment threadLib/test/string_tests.py Outdated
@XChaitanyaX

Copy link
Copy Markdown
ContributorAuthor

self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a')

self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6)

are the leading whitespaces just before 2 kept for readability??

Comment threadLib/test/string_tests.py Outdated
Comment threadLib/test/string_tests.py Outdated

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

Thank you for your contribution, @XChaitanyaX.

@serhiy-storchaka
serhiy-storchaka merged commit e6174ee into python:mainNov 25, 2025
50 checks passed
@serhiy-storchakaserhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Nov 25, 2025
@miss-islington-app

Copy link
Copy Markdown

Thanks @XChaitanyaX for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @XChaitanyaX for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 25, 2025
…() accept UserString as argument (pythonGH-140945)
(cherry picked from commit e6174ee)
Co-authored-by: Krishna Chaitanya <141550576+XChaitanyaX@users.noreply.github.com>
@bedevere-app

Copy link
Copy Markdown

GH-141945 is a backport of this pull request to the 3.13 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.13 bugs and security fixes label Nov 25, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 25, 2025
…() accept UserString as argument (pythonGH-140945)
(cherry picked from commit e6174ee)
Co-authored-by: Krishna Chaitanya <141550576+XChaitanyaX@users.noreply.github.com>
@bedevere-app

Copy link
Copy Markdown

GH-141946 is a backport of this pull request to the 3.14 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.14 bugs and security fixes label Nov 25, 2025
serhiy-storchaka pushed a commit that referenced this pull request Nov 25, 2025
…x() accept UserString as argument (GH-140945) (GH-141945)
(cherry picked from commit e6174ee)
Co-authored-by: Krishna Chaitanya <141550576+XChaitanyaX@users.noreply.github.com>
serhiy-storchaka pushed a commit that referenced this pull request Nov 25, 2025
…x() accept UserString as argument (GH-140945) (GH-141946)
(cherry picked from commit e6174ee)
Co-authored-by: Krishna Chaitanya <141550576+XChaitanyaX@users.noreply.github.com>
@XChaitanyaX
XChaitanyaX deleted the pr_140911 branch November 25, 2025 14:32
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
ashm-dev pushed a commit to ashm-dev/cpython that referenced this pull request Dec 8, 2025
@@ -295,6 +277,19 @@ def test_index(self):
else:
self.checkraises(TypeError, 'hello', 'index', 42)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.checkraises(TypeError, 'hello', 'index', 42)
self.checkraise

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@XChaitanyaX@serhiy-storchaka@PredictiveManish@asifhaniff10-alt