Title: Store StopIteration.value in a struct field instead of the instance dict by kangdora · Pull Request #8301 · RustPython/RustPython · GitHub
Open Graph Title: Store StopIteration.value in a struct field instead of the instance dict by kangdora · Pull Request #8301 · RustPython/RustPython
X Title: Store StopIteration.value in a struct field instead of the instance dict by kangdora · Pull Request #8301 · RustPython/RustPython
Description: Closes #8290 This PR follows our AI policy Summary StopIteration.value was stored in the instance __dict__, so StopIteration().__dict__ was non-empty and clearing the dict lost the value, unlike CPython. It's now a struct field on PyStopIteration (#[repr(C)] + base field, the same approach as OSError and SystemExit in #8282), exposed via #[pygetset] — writable, deletable, and independent from args, with an empty __dict__ as in CPython. new_stop_iteration is also routed through the full constructor path instead of building a PyBaseException with a manual dict. This fixes a crash caused by the added payload (the old path allocated a base-sized object) and removes the per-instance dict allocation on this hot path. e = StopIteration(5) e.__dict__.clear() print(e.value) # before: None after: 5 (matches CPython) Test plan Verified against CPython 3.14.6: value for StopIteration() / (5) / (1, 2), write/delete, dict.clear(), vars(), empty __dict__, and generator return value delivery (incl. yield from). test_generators, test_generator_stop, test_yield_from: all pass. test_exceptions / extra_tests/snippets/builtin_exceptions.py: no regressions (the single test_badisinstance failure is pre-existing on main). cargo fmt / cargo clippy: clean (no new warnings). Unmarks test_pydoc's test_member_descriptor: it now passes because StopIteration.value is a real descriptor whose pydoc summary line renders as value (it was previously a plain None class attribute). Note this does not add __doc__ support to getset descriptors — StopIteration.value.__doc__ still differs from CPython, which is a separate pre-existing gap in PyGetSet. Assisted-by: Claude Code:claude-fable-5 Summary by CodeRabbit Summary by CodeRabbit Bug Fixes Improved StopIteration exception handling and initialization to make the exception’s value reliably accessible and updatable. Standardized how StopIteration is constructed, ensuring the return payload is consistently preserved whether a value is provided or not.
Open Graph Description: Closes #8290 This PR follows our AI policy Summary StopIteration.value was stored in the instance __dict__, so StopIteration().__dict__ was non-empty and clearing the dict lost the value, unlike ...
X Description: Closes #8290 This PR follows our AI policy Summary StopIteration.value was stored in the instance __dict__, so StopIteration().__dict__ was non-empty and clearing the dict lost the value, unlike ...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8301
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:fe570c88-9db2-a5bd-3a62-faa5fc6e4432 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AF9A:2D8BE0:8CE7E2:B7B000:6A60047C |
| html-safe-nonce | 19c8b6a9b4e7e975bc4f116e522b7b906e24cc61bbf102205880ab4fcb266a59 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjlBOjJEOEJFMDo4Q0U3RTI6QjdCMDAwOjZBNjAwNDdDIiwidmlzaXRvcl9pZCI6IjU2NzcwMTgxOTk0NjIyNDk1OTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 485a016141900f66d05008d06dbab8f39a30dee5cbc139d0a59d6e2f6997372b |
| hovercard-subject-tag | pull_request:4074033893 |
| 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/8301/files |
| twitter:image | https://avatars.githubusercontent.com/u/182498567?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/182498567?s=400&v=4 |
| og:image:alt | Closes #8290 This PR follows our AI policy Summary StopIteration.value was stored in the instance __dict__, so StopIteration().__dict__ was non-empty and clearing the dict lost the value, unlike ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5789899e92b20db289de946d86eb20bf5c9626276695d68f58a8c47cdda699b7 |
| 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 | 6ddc048ddf80664b9b33547b619db10313c482f1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width