Title: fallback: return bytes from Unpacker.read_bytes by Cherith1222 · Pull Request #747 · msgpack/msgpack-python · GitHub
Open Graph Title: fallback: return bytes from Unpacker.read_bytes by Cherith1222 · Pull Request #747 · msgpack/msgpack-python
X Title: fallback: return bytes from Unpacker.read_bytes by Cherith1222 · Pull Request #747 · msgpack/msgpack-python
Description: Unpacker.read_bytes() in the C extension returns bytes. The pure-Python fallback returned a bytearray slice of its buffer. The values compare equal, so the existing content checks still passed, but a bytearray cannot be a dict key: import msgpack unpacker = msgpack.Unpacker() unpacker.feed(b"foobar") unpacker.unpack() got = unpacker.read_bytes(3) {got: 1} On the C extension, got is b"oob" and the dict succeeds. With MSGPACK_PUREPYTHON=1, got was a bytearray and that line raised TypeError: unhashable type: 'bytearray'. read_bytes() now wraps that slice in bytes() before returning. Reads inside the unpacker still use the bytearray buffer. A feed that does not yet contain n bytes still raises OutOfData and leaves those bytes unconsumed. This is Finding 4 in #683. The other items in that issue are not part of this change. AI-assisted (Cursor). Cherith reviewed this diff and confirmed it with the person who helped draft it. Test plan Before this change, test_read_bytes_returns_bytes failed on Windows, Python 3.13.3, with type(got) as bytearray. After it, MSGPACK_PUREPYTHON=1 pytest test: 141 passed, 4 skipped. test/test_sequnpack.py and test/test_unpack.py: 16 passed, 2 skipped. The same assertions succeed against the msgpack 1.2.3 Windows wheel (msgpack._cmsgpack). read_bytes in _unpacker.pyx is unchanged since that release. This machine has no MSVC, so the C extension was not built from this checkout. ruff check and ruff format --check passed on the two edited files.
Open Graph Description: Unpacker.read_bytes() in the C extension returns bytes. The pure-Python fallback returned a bytearray slice of its buffer. The values compare equal, so the existing content checks still passed, but...
X Description: Unpacker.read_bytes() in the C extension returns bytes. The pure-Python fallback returned a bytearray slice of its buffer. The values compare equal, so the existing content checks still passed, but...
Opengraph URL: https://github.com/msgpack/msgpack-python/pull/747
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
| 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:2dcf2fdd-0dbc-e885-68b5-22db767300e9 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AD82:2951FF:570902:74A4A0:6B078C72 |
| html-safe-nonce | 07e18b06de5da0a03e07cd5de2d40de506783ddd546fe3b2108426c068b555af |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDgyOjI5NTFGRjo1NzA5MDI6NzRBNEEwOjZCMDc4QzcyIiwidmlzaXRvcl9pZCI6Ijc5MDE2Nzc4NTcxMTcwMTUxNTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9d7a883e5c3ee2752cdabfbfb7a19c56c19089a16c6622287f8974562f2605ea |
| hovercard-subject-tag | pull_request:4815017719 |
| 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/msgpack/msgpack-python/pull/747/files |
| twitter:image | https://avatars.githubusercontent.com/u/315844584?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/315844584?s=400&v=4 |
| og:image:alt | Unpacker.read_bytes() in the C extension returns bytes. The pure-Python fallback returned a bytearray slice of its buffer. The values compare equal, so the existing content checks still passed, but... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 176c580172ff5ad9b9613f91a521417cd790cd3d786513ed70487aa605a0c30d |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/msgpack/msgpack-python git https://github.com/msgpack/msgpack-python.git |
| octolytics-dimension-user_id | 198264 |
| octolytics-dimension-user_login | msgpack |
| octolytics-dimension-repository_id | 2242705 |
| octolytics-dimension-repository_nwo | msgpack/msgpack-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 2242705 |
| octolytics-dimension-repository_network_root_nwo | msgpack/msgpack-python |
| 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 | 097bab580a566ddf462cc02dca974461f9854cf3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width