Title: test_str: the UCS4 adaptive search path is never exercised · Issue #160501 · python/cpython · GitHub
Open Graph Title: test_str: the UCS4 adaptive search path is never exercised · Issue #160501 · python/cpython
X Title: test_str: the UCS4 adaptive search path is never exercised · Issue #160501 · python/cpython
Description: Summary Objects/stringlib/fastsearch.h compiles adaptive_find once per character width. The UCS4 copy never ran under the entire test suite, because the only test that reaches the adaptive path, string_tests.BaseTest.test_adaptive_find, ...
Open Graph Description: Summary Objects/stringlib/fastsearch.h compiles adaptive_find once per character width. The UCS4 copy never ran under the entire test suite, because the only test that reaches the adaptive path, st...
X Description: Summary Objects/stringlib/fastsearch.h compiles adaptive_find once per character width. The UCS4 copy never ran under the entire test suite, because the only test that reaches the adaptive path, st...
Opengraph URL: https://github.com/python/cpython/issues/160501
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_str: the UCS4 adaptive search path is never exercised","articleBody":"## Summary\n\n`Objects/stringlib/fastsearch.h` compiles `adaptive_find` once per character\nwidth. The UCS4 copy never ran under the entire test suite, because the only test\nthat reaches the adaptive path, `string_tests.BaseTest.test_adaptive_find`, uses\nASCII strings.\n\n## Evidence\n\nCoverage from a `--coverage` build of main running the full suite\n(`./python -m test -j4`, 552 files, 52,070 tests):\n\n```text\nFunction 'ucs4lib_adaptive_find' Lines executed:0.00% of 39\nFunction 'ucs2lib_adaptive_find' Lines executed:66.67% of 39\nFunction 'ucs1lib_adaptive_find' Lines executed:71.79% of 39\nFunction 'asciilib_adaptive_find' Lines executed:79.49% of 39\n```\n\n## Why the existing test misses it\n\nThe adaptive branch is taken only when, in `Objects/stringlib/fastsearch.h:800`:\n\n- the haystack is at least 2500 characters,\n- the needle is at least 100 characters (or the haystack at least 30000),\n- the needle is at least a third of the haystack.\n\n`test_adaptive_find` meets all three, but with `'a'` and `'b'`, so the code that\nruns is the ASCII or UCS1 instantiation. Nothing in the suite builds a haystack\nthat wide-and-long out of non-BMP characters, so the UCS4 instantiation stays\ncold.\n\n## Proposal\n\nAdd a test next to `test_find` in `Lib/test/test_str.py` that repeats the same\nshape with `'\\U0001d11e'` and `'\\U0001d11f'`. With that test present,\n`ucs4lib_adaptive_find` goes from 0.00% to 89.74% of 39 lines, and the remaining\nbranches are the count and reverse-search modes, which are separate entry points.\n\nThis is a test-only change, so it does not alter behaviour. I have it ready and\nwill open a PR against this issue.\n\n### CPython versions tested on\n\nCPython main branch (3.16.0a1+)\n\n### Operating systems tested on\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-160502\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/scrieve","@type":"Person","name":"scrieve"},"datePublished":"2026-10-23T20:47:25Z","url":"https://github.com/python/cpython/issues/160501"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0296b4c9-80ab-b3a5-1e40-8fda75e8195a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9AD6:1F82:3CB112:4F59B3:6B023F36 |
| html-safe-nonce | 3d16303c2f385ab33d2c03fcf6b1c5193b2cb5e53eb92f118e89cc4b062901e6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUQ2OjFGODI6M0NCMTEyOjRGNTlCMzo2QjAyM0YzNiIsInZpc2l0b3JfaWQiOiI2MzEzMTY4NDkxNzAwNjk4OTM0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 35ffc1ba6f3e96666c371db50fa33570f06a6cb17ea70a7b594ac83377e8652b |
| hovercard-subject-tag | issue:6005212469 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/160501/issue_layout |
| twitter:image | https://opengraph.githubassets.com/642d6585a4d412a4537eb542d506a5f6ae1fda4746bfda6c2ae173749abf656b/python/cpython/issues/160501 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/642d6585a4d412a4537eb542d506a5f6ae1fda4746bfda6c2ae173749abf656b/python/cpython/issues/160501 |
| og:image:alt | Summary Objects/stringlib/fastsearch.h compiles adaptive_find once per character width. The UCS4 copy never ran under the entire test suite, because the only test that reaches the adaptive path, st... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | scrieve |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width