-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Fix indices handling in PyUnicode_FindChar #73008
Comments
PyUnicode_FindChar declares in the doc it treats its *start* and *end* parameters as str[start:end], same as other APIs like PyUnicode_Find, PyUnicode_Count. But it doesn't allow negative indices like others so violates the doc. |
PyUnicode_FindChar.patch is a new feature, it cannot be applied to stable branches (py < 3.7). I'm not sure that it's worth it to support negative indexes for end. Why not simply documenting that end must be positive? |
Other APIs like PyUnicode_Find and PyUnicode_Count support it. Their docs are almost the same so I think PyUnicode_FindChar does not need to be the special one. After change, its behaviour and implementation are more consistent with other APIs. |
Serhiy: I don't think that it's worth it to add a new function to _testcapi to test PyUnicode_FindChar. The implementation of the function seems simple. At least, I would prefer to only see a few unit tests, not 17 test for this simple function! I mean "character in str" is already tested by a *lot* of unit tests. |
I think it is nice to add tests for C API. Especially if there is no direct mapping between Python and C API ("character in str" don't call PyUnicode_FindChar()). Tests should cover all corner cases, otherwise we can miss bugs. Some C API can be not used in CPython at all, just in third-party extensions, and special tests is the only way to test them. The implementation of PyUnicode_FindChar() is not so simple (for example see bpo-24821). I don't have an opinion about supporting negative indices. |
Would be nice to test corner cases:
|
Thanks for your reviews. :-) v2 updated the test codes. |
PyUnicode_FindChar-v2.patch LGTM with a minor comment on the review, but I would prefer that Serhiy also reviews it ;-) Remaining question: what is the behaviour for direction=0, direction=100 or direction=-2? Maybe we can add a few unit tests for strange values of direction? (Not sure if it's worth it.) |
It's not documented so I also doubt it. Expect Serhiy's comment. |
Ignore my request about special direction values. It's not worth it to writ tests for that. PyUnicode_FindChar-v2.patch LGTM. |
New changeset ce6a6cc3765d by Xiang Zhang in branch 'default': |
Thanks Victor and Serhiy! |
New changeset 2b5e5a3a805e by Martin Panter in branch 'default': |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: