Title: Match CPython's str subscript TypeError message by kim-jaedeok · Pull Request #8319 · RustPython/RustPython · GitHub
Open Graph Title: Match CPython's str subscript TypeError message by kim-jaedeok · Pull Request #8319 · RustPython/RustPython
X Title: Match CPython's str subscript TypeError message by kim-jaedeok · Pull Request #8319 · RustPython/RustPython
Description: Summary Make str subscripting with a non-integer index raise the same TypeError message as CPython, and drop the expectedFailure marker on string_tests.test_subscript. Before / after ('abc'['def']): message CPython 3.14 string indices must be integers, not 'str' RustPython (before) str indices must be integers or slices or classes that override __index__ operator, not 'str' RustPython (after) string indices must be integers, not 'str' Only the error message differed — indexing itself (int / negative / slice) already behaved correctly. CPython gives str its own wording in unicode_subscript (see python/cpython#88276, fixed in 3.11), distinct from the shared sequence message used by list/tuple/bytes. Approach Add SequenceIndex::try_from_borrowed_object_with_err, which keeps the shared index-parsing logic but lets the caller supply the TypeError raised for a non-index object. try_from_borrowed_object now delegates to it with the existing wording, so every other sequence caller (list/tuple/bytes/bytearray/array/mmap/ struct-sequence) is byte-for-byte unchanged. str::_getitem — the single path shared by __getitem__ and the mapping subscript slot — supplies the CPython-accurate message. Scoped intentionally to str only: CPython declined to unify the sequence messages (python/cpython#75731, rejected), so the other types' wording is left as-is. Testing test_str / test_userstring test_subscript now pass (marker removed). Byte-for-byte match with CPython 3.14.6 for str/object/None/float indices, and for UserString as receiver. list/tuple/bytes messages verified unchanged; rustpython-vm and rustpython-codegen unit tests pass. Summary by CodeRabbit Bug Fixes Improved error messages for invalid string indices. String indexing with a non-integer value now raises a clear TypeError identifying the invalid type. Standardized handling of invalid sequence indices for more consistent behavior.
Open Graph Description: Summary Make str subscripting with a non-integer index raise the same TypeError message as CPython, and drop the expectedFailure marker on string_tests.test_subscript. Before / after ('abc'...
X Description: Summary Make str subscripting with a non-integer index raise the same TypeError message as CPython, and drop the expectedFailure marker on string_tests.test_subscript. Before / after ('abc&...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8319
X: @github
Domain: Github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:ab5606c8-a9a1-0331-47ac-a46cc4339648 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A56C:377B45:B330A8:FFADAF:6A631B5A |
| html-safe-nonce | 2629c5f96f7f48b8a60183462271f353413c45052170ac53e2899310ca048af2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTZDOjM3N0I0NTpCMzMwQTg6RkZBREFGOjZBNjMxQjVBIiwidmlzaXRvcl9pZCI6IjIyOTg2NDI5OTIyNDgwNjg5NTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1bc6df889cd5df542fc0116706aaca62ef96d2a0f68b44b872d7aa28903425f9 |
| hovercard-subject-tag | pull_request:4083381521 |
| 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/8319/files |
| twitter:image | https://avatars.githubusercontent.com/u/89368498?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/89368498?s=400&v=4 |
| og:image:alt | Summary Make str subscripting with a non-integer index raise the same TypeError message as CPython, and drop the expectedFailure marker on string_tests.test_subscript. Before / after ('abc'... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1a6c056e02f174fffc096c521ec0ff6fb83e40a2ec8cb8875466ec1524872dd6 |
| 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 | 6a93e25585f487ddff9e3996c06d5b869d6e1828 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width