Title: Store SyntaxError members in struct fields instead of the instance dict by devyubin · Pull Request #8348 · RustPython/RustPython · GitHub
Open Graph Title: Store SyntaxError members in struct fields instead of the instance dict by devyubin · Pull Request #8348 · RustPython/RustPython
X Title: Store SyntaxError members in struct fields instead of the instance dict by devyubin · Pull Request #8348 · RustPython/RustPython
Description: Part of #8345 This PR follows our AI policy Summary SyntaxError's members were stored as None class-attribute placeholders plus per-instance __dict__ entries, so SyntaxError('m').__dict__ was non-empty ({'print_file_and_line': None}, plus filename/lineno/offset/text for the (msg, tuple) form) unlike CPython, and they weren't backed by descriptors. They're now struct fields on PySyntaxError (#[repr(C)] + base field, the same approach as SystemExit in #8282 and StopIteration in #8301), exposed via #[pygetset] — writable, deletable, independent from args, with an empty __dict__ as in CPython. IndentationError, TabError, and _IncompleteInputError inherit the fields. Re-initialization now resets end_lineno/end_offset, so a 4-element location tuple after a 6-element one no longer keeps stale values (matches CPython's gh-146250 fix): e = SyntaxError("msg", ("file.py", 1, 2, "txt", 2, 3)) e.__init__("new", ("new.py", 4, 5, "t")) print(e.end_lineno, e.end_offset) # before: 2 3 after: None None (matches CPython) new_exception is also routed through the real constructor for exception types that carry additional payload (now including SyntaxError), instead of building a base-sized PyBaseException. Without this, the compile-error path (new_exception_msg(syntax_error, …), ~15 call sites) would allocate a wrong-sized payload — a debug-assert panic, and out-of-bounds reads in release. Test plan Verified against CPython 3.14.6: msg/filename/lineno/offset/text/end_lineno/end_offset for SyntaxError(), the 4-tuple, and the 6-tuple forms; write/delete; re-init reset; empty __dict__; IndentationError/TabError inheritance; and the compile-error path (compile("1 +", ...) renders the caret and sets lineno/msg). test_exceptions: no regressions — test_syntax_error_memory_leak now passes; the single test_badisinstance failure is pre-existing on main (an unrelated empty-message RecursionError). test_syntax / test_compile: pass. cargo fmt / cargo clippy: clean (no new warnings). Unmarks test_exceptions's test_syntax_error_memory_leak (removes its @expectedFailure) — it now passes. Notes: Like StopIteration.value in #8301, the members are getset_descriptors rather than CPython's member_descriptors; both are data descriptors and behave the same for get/set/delete. msg is initialized in the constructor (not only __init__) so TabError still renders its message. TabError's __init__ slot is not reached during construction — a pre-existing limitation for two-level exception subclasses — so its location members (lineno/offset/…) are not populated from a direct TabError(msg, tuple) call; the compile path sets them via attribute assignment, so raised TabErrors are unaffected. Fixing that inheritance is out of scope here. Assisted-by: Claude Code:claude-fable-5 Summary by CodeRabbit Bug Fixes Improved SyntaxError handling for message, filename, line number, offset, source text, and end-position details. Added stricter validation for how location information is provided, including correct handling of supported shapes and end-position constraints. Improved exception creation compatibility when exception types use different internal payload layouts.
Open Graph Description: Part of #8345 This PR follows our AI policy Summary SyntaxError's members were stored as None class-attribute placeholders plus per-instance __dict__ entries, so SyntaxError('m').__d...
X Description: Part of #8345 This PR follows our AI policy Summary SyntaxError's members were stored as None class-attribute placeholders plus per-instance __dict__ entries, so SyntaxError('m&a...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8348
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:3ad49c48-d9d4-e98f-a184-1d6a069bef93 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ED0E:2F9718:30B5293:4151CE4:6B01FA0A |
| html-safe-nonce | 72d28922f3b676683f1ffcd83e1506a4ba48d8bcf761241c5bae1551b518d623 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDBFOjJGOTcxODozMEI1MjkzOjQxNTFDRTQ6NkIwMUZBMEEiLCJ2aXNpdG9yX2lkIjoiNTcwNjUxMjk1NDM0Nzk5NjI2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0e4f42fdd3774380f05ce9ce6089bcf2cf8bc8552ffdc06586cfb82dda58f4ab |
| hovercard-subject-tag | pull_request:4108404848 |
| 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/8348/files |
| twitter:image | https://avatars.githubusercontent.com/u/80163835?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/80163835?s=400&v=4 |
| og:image:alt | Part of #8345 This PR follows our AI policy Summary SyntaxError's members were stored as None class-attribute placeholders plus per-instance __dict__ entries, so SyntaxError('m').__d... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width