Title: Several built-in exceptions store their attributes in the instance dict instead of as fields · Issue #8345 · RustPython/RustPython · GitHub
Open Graph Title: Several built-in exceptions store their attributes in the instance dict instead of as fields · Issue #8345 · RustPython/RustPython
X Title: Several built-in exceptions store their attributes in the instance dict instead of as fields · Issue #8345 · RustPython/RustPython
Description: Feature Several built-in exceptions store their attributes in the instance __dict__ instead of as struct fields, so Exc().__dict__ is non-empty (unlike CPython) and the attributes are not backed by descriptors. SystemExit.code (#8230 / #...
Open Graph Description: Feature Several built-in exceptions store their attributes in the instance __dict__ instead of as struct fields, so Exc().__dict__ is non-empty (unlike CPython) and the attributes are not backed by...
X Description: Feature Several built-in exceptions store their attributes in the instance __dict__ instead of as struct fields, so Exc().__dict__ is non-empty (unlike CPython) and the attributes are not backed by...
Opengraph URL: https://github.com/RustPython/RustPython/issues/8345
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Several built-in exceptions store their attributes in the instance dict instead of as fields","articleBody":"## Feature\n\nSeveral built-in exceptions store their attributes in the instance `__dict__` instead of as struct fields, so `Exc().__dict__` is non-empty (unlike CPython) and the attributes are not backed by descriptors. `SystemExit.code` (#8230 / #8282) and `StopIteration.value` (#8290 / #8301) have been converted already; this issue tracks the rest.\n\nMeasured against CPython 3.14.6 (`print(exc.__dict__)`):\n\n| exception | leaked into `__dict__` | CPython |\n|---|---|---|\n| `NameError('m', name='x')` | `{'name': 'x'}` | `{}` |\n| `AttributeError('m')` | `{'name': None, 'obj': None}` | `{}` |\n| `ImportError('m')` | `{'name': None, 'path': None, 'name_from': None}` | `{}` |\n| `SyntaxError('m')` | `{'print_file_and_line': None}` | `{}` |\n| `SyntaxError('m', (...))` | `+ filename, lineno, offset, text` | `{}` |\n| `UnicodeDecodeError(...)` | `{'encoding', 'object', 'start', 'end', 'reason'}` | `{}` |\n| `UnicodeEncodeError(...)` | same five fields | `{}` |\n| `UnicodeTranslateError(...)` | `{'object', 'start', 'end', 'reason'}` | `{}` |\n\nTheir subclasses inherit the same problem (`ModuleNotFoundError` from `ImportError`; `IndentationError` / `TabError` / `_IncompleteInputError` from `SyntaxError`) and should be fixed automatically once the base is converted.\n\nThese are the remaining cases of the issue addressed in #8282 and #8301.\n`SyntaxError` already carries a `// TODO: members` note for this.\n\n## Plan\n\nConvert each to a struct field (`#[repr(C)]` + base field, exposed via `#[pygetset]`), following the approach established in #8282 and #8301, in separate PRs:\n\n1. `NameError` and `AttributeError`\n * Both are small and use a similar keyword-argument pattern.\n2. `ImportError`\n * `ModuleNotFoundError` will inherit the converted fields.\n3. `UnicodeDecodeError`, `UnicodeEncodeError`, and `UnicodeTranslateError`\n * These exceptions share most of their fields, similar to CPython's implementation.\n4. `SyntaxError`\n * This will also cover `IndentationError`, `TabError`, and `_IncompleteInputError`.\n * It is the largest conversion and will require checking the code paths that read these attributes.\n\n\n## Python Documentation or reference to CPython source code\n\nhttps://docs.python.org/3/library/exceptions.html\n\nThese attributes are defined via `PyMemberDef` (struct members, not instance-dict entries) in CPython's `Objects/exceptions.c`.\n\n---\nVerified locally against CPython 3.14.6 and RustPython. AI was used to help organize the initial draft; the technical details and final wording were reviewed by me.","author":{"url":"https://github.com/kangdora","@type":"Person","name":"kangdora"},"datePublished":"2026-07-21T13:47:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/8345/RustPython/issues/8345"}
| 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:30447097-9572-6ec6-1953-765525972d52 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A76C:2DCA08:17785:2068D:6A610B57 |
| html-safe-nonce | b6a261e97dd922cceabc946d353dc5de5f0bc1a1945166f3de4e9e781d41ae7d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzZDOjJEQ0EwODoxNzc4NToyMDY4RDo2QTYxMEI1NyIsInZpc2l0b3JfaWQiOiI0NDUzMjg1MjIxMTUzOTY2OTM1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c19a921a4f6b82a5c48651b9f5f418ccf3ffcc9de7e7c8ee75edf41f3eefbfa8 |
| hovercard-subject-tag | issue:4939558756 |
| 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/RustPython/RustPython/8345/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f871d56d147141de12c1a916ebbc9cf3685979259dfdb807c39e939cdf3bfa2e/RustPython/RustPython/issues/8345 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f871d56d147141de12c1a916ebbc9cf3685979259dfdb807c39e939cdf3bfa2e/RustPython/RustPython/issues/8345 |
| og:image:alt | Feature Several built-in exceptions store their attributes in the instance __dict__ instead of as struct fields, so Exc().__dict__ is non-empty (unlike CPython) and the attributes are not backed by... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kangdora |
| hostname | github.com |
| expected-hostname | github.com |
| None | 86be97fd69ac233b46e43a5eed04ceac6498abe1efaf1af3b9573eb216019c05 |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f80280886562a52fe1f6b9cab9f9c1dc3b9a78a2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width