Title: Apply titlecase mapping in str.title() for uppercase digraphs by changjoon-park · Pull Request #7748 · RustPython/RustPython · GitHub
Open Graph Title: Apply titlecase mapping in str.title() for uppercase digraphs by changjoon-park · Pull Request #7748 · RustPython/RustPython
X Title: Apply titlecase mapping in str.title() for uppercase digraphs by changjoon-park · Pull Request #7748 · RustPython/RustPython
Description: Background PyStr::title() (crates/vm/src/builtins/str.rs:1040) walks each codepoint and chooses one of three actions per word boundary: Lowercase character starting a new word → call to_titlecase() Uppercase / titlecase character starting a new word → push unchanged Cased character continuing a word → call to_lowercase() Branch 2 is the gap. For ASCII letters and most Unicode characters, to_titlecase(c) == c, so pushing unchanged happens to produce the right result. But Latin Extended-B contains digraph triplets (LATIN LETTERS DZ / DŽ / LJ / NJ) where the uppercase and titlecase forms are distinct codepoints: Codepoint Form U+01C4 'DŽ' uppercase DŽ U+01C5 'Dž' titlecase Dž U+01C6 'dž' lowercase dž U+01F1 'DZ' uppercase DZ U+01F2 'Dz' titlecase Dz U+01F3 'dz' lowercase dz For these, c.to_titlecase() returns a different character than c itself, and the Branch 2 fall-through silently produced the wrong output. Reproduction 'DZ'.title() # CPython: 'Dz' Pre-fix: 'DZ' 'DŽ'.title() # CPython: 'Dž' Pre-fix: 'DŽ' 12 cases probed against CPython 3.14.4 covering all 4 digraph families × 3 forms each (uppercase / titlecase / lowercase): Family upper.title() title.title() lower.title() DŽ (U+01C4-01C6) Dž ✓ Dž ✓ Dž ✓ LJ (U+01C7-01C9) Lj ✓ Lj ✓ Lj ✓ NJ (U+01CA-01CC) Nj ✓ Nj ✓ Nj ✓ DZ (U+01F1-01F3) Dz ✓ Dz ✓ Dz ✓ Fix } else if c.is_uppercase() || c.is_titlecase() { if previous_is_cased { title.extend(c.to_lowercase()); } else { title.extend(c.to_titlecase()); // was: title.push_char(c) } previous_is_cased = true; } The lowercase branch (line 1047) already uses c.to_titlecase() — Branch 2 is now symmetric. char::to_titlecase returns the same character when invoked on an ASCII letter or already-titlecase codepoint, so no existing case regresses. Verification CPython 3.14.4 byte-identical across: 12 single-codepoint digraph cases — all 4 families × 3 forms 8 mixed-string cases — digraphs at start, mid-word, as standalone word, consecutive digraphs, multi-word strings ('hello DZ world' → 'Hello Dz World') 14 sibling-method cases — upper, lower, swapcase, capitalize, casefold, istitle on digraphs unchanged New Rust unit cases added to str_title (crates/vm/src/builtins/str.rs:2664) covering U+01F1 → U+01F2 and U+01C4 → U+01C5. cargo test -p rustpython-vm str_title and str_istitle both pass. Regression sweep: test_str, test_codecs, test_format, test_pprint — 484 tests, 0 regressions. No expectedFailure markers in Lib/test/test_str.py are tied to this root cause; this PR has no test unmask. Issue scope note Issue #7527 listed five examples. Probing on current main shows four already pass: Issue example Status on current main ''.istitle() == False Stale: CPython 3.14.4 itself returns True for this codepoint 'DZ'.title() == 'Dz' Still failing — fixed by this PR '١'.isdigit() == True Already passes 'ౝ'.isidentifier() == True Already passes '㐅'.isnumeric() == True Already passes This PR closes the only remaining actionable case. The .istitle() expected value in the issue body appears to predate a Unicode database update in CPython 3.14 — current CPython behavior matches RustPython. Closes #7527 Summary by CodeRabbit Bug Fixes Corrected title-casing for Unicode characters whose titlecase mapping expands to multiple characters (including Latin Extended‑B digraphs), so title() now produces proper multi-character expansions and consistent title-case output across scripts.
Open Graph Description: Background PyStr::title() (crates/vm/src/builtins/str.rs:1040) walks each codepoint and chooses one of three actions per word boundary: Lowercase character starting a new word → call to_titlecase(...
X Description: Background PyStr::title() (crates/vm/src/builtins/str.rs:1040) walks each codepoint and chooses one of three actions per word boundary: Lowercase character starting a new word → call to_titlecase(...
Opengraph URL: https://github.com/RustPython/RustPython/pull/7748
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:fadb5264-43c4-80ae-2243-9b68e826eb1e |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A7FC:39AD58:33871F0:47DE1AD:6A60DA38 |
| html-safe-nonce | d83d107a3046d4a71e7b958be60718a86e15d0255fc471cd429ee1c6a742779d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0ZDOjM5QUQ1ODozMzg3MUYwOjQ3REUxQUQ6NkE2MERBMzgiLCJ2aXNpdG9yX2lkIjoiNDM0MTc4MTQxOTEwODkxNTc2OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 649b72d7659a6813a1b25aa701edce6073eabbc32312881a3ed3eadda26f8c65 |
| hovercard-subject-tag | pull_request:3613117978 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/RustPython/RustPython/pull/7748/files |
| twitter:image | https://avatars.githubusercontent.com/u/131537123?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/131537123?s=400&v=4 |
| og:image:alt | Background PyStr::title() (crates/vm/src/builtins/str.rs:1040) walks each codepoint and chooses one of three actions per word boundary: Lowercase character starting a new word → call to_titlecase(... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8302bdfafed4cf34ac9c1d3593108fafa53bc3f86b893907e38fa6bdd74361ac |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c3c2ff0c76b34772c83c9498a08cefee28f53da0 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width