Title: Change some implementation details in struct.Struct · Issue #145850 · python/cpython · GitHub
Open Graph Title: Change some implementation details in struct.Struct · Issue #145850 · python/cpython
X Title: Change some implementation details in struct.Struct · Issue #145850 · python/cpython
Description: struct.Struct() accepts format as a string or a bytes object. It stores the format as the bytes object, but the format getter returns a string (see bpo-21071/gh-65270). While not yet initialized, it stores None, since gh-78724 the getter...
Open Graph Description: struct.Struct() accepts format as a string or a bytes object. It stores the format as the bytes object, but the format getter returns a string (see bpo-21071/gh-65270). While not yet initialized, i...
X Description: struct.Struct() accepts format as a string or a bytes object. It stores the format as the bytes object, but the format getter returns a string (see bpo-21071/gh-65270). While not yet initialized, i...
Opengraph URL: https://github.com/python/cpython/issues/145850
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Change some implementation details in struct.Struct","articleBody":"`struct.Struct()` accepts format as a string or a bytes object. It stores the format as the bytes object, but the `format` getter returns a string (see bpo-21071/gh-65270). While not yet initialized, it stores None, since gh-78724 the getter raises RuntimeError in such case (it returned None prior to gh-65270 and crashed prior to gh-78724). The getter could also raise an UnicodeDecodeError prior to gh-145743.\n\nThis all is a Python 2 legacy. We can simply store format as a string, this will simplify the getter. We can also use NULL instead of None as the default value, and use read-only members instead of a getter. This will make the code more strightforward.\n\nThis will have user visible effects:\n\n* Non-ASCII string format will lead to ValueError (or better use struct.error?) instead of UnicodeEncodeError.\n* Non-ASCII bytes format will lead to ~UnicodeDecodeError~ ValueError instead of struct.error.\n* Getting the `format` attribute of uninitialized `Struct` will lead to AttributeError instead of RuntimeError.\n\nThese cases normally do not occur in the user code, and the current exceptions is simply an implementation detail.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-145851\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-03-12T10:05:17Z","url":"https://github.com/python/cpython/issues/145850"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:300e7213-8b9c-41b3-8326-a74fdfa52142 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ADC4:B9AA0:429858:5BD904:6AECCC02 |
| html-safe-nonce | fc50366ad8fcc608e357822419d327128e01a28c8843cd57a20fbe4e9c42fd00 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREM0OkI5QUEwOjQyOTg1ODo1QkQ5MDQ6NkFFQ0NDMDIiLCJ2aXNpdG9yX2lkIjoiODk1OTU4NTA1NTgxNzkxMTI5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7f6fc9f3881e713eaf3041775fddd8619ed61dbf1a116cefbd8fadb9586fc700 |
| hovercard-subject-tag | issue:4063536194 |
| 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/python/cpython/145850/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53f6a11b01fdc82dd8d7dbde02010cb0633de5535ec73ea39a5d310ec712816f/python/cpython/issues/145850 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53f6a11b01fdc82dd8d7dbde02010cb0633de5535ec73ea39a5d310ec712816f/python/cpython/issues/145850 |
| og:image:alt | struct.Struct() accepts format as a string or a bytes object. It stores the format as the bytes object, but the format getter returns a string (see bpo-21071/gh-65270). While not yet initialized, i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | dc0b519c5798dc1150b88dc4c06a8b9634d0069218dc04e469970e76aad74016 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | db139f0bf57b59bf9a8c4abb0849924d6c6ca559 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width