Title: Failed BytesIO reinitialization mutates the stream's position and contents · Issue #157048 · python/cpython · GitHub
Open Graph Title: Failed BytesIO reinitialization mutates the stream's position and contents · Issue #157048 · python/cpython
X Title: Failed BytesIO reinitialization mutates the stream's position and contents · Issue #157048 · python/cpython
Description: Bug report Bug description: Python 3.16.0a0 (heads/main:09117bc, Sep 6 2026, 15:04:05) [Clang 21.0.0 (clang-2100.1.1.101)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import io ... ... stream = io...
Open Graph Description: Bug report Bug description: Python 3.16.0a0 (heads/main:09117bc, Sep 6 2026, 15:04:05) [Clang 21.0.0 (clang-2100.1.1.101)] on darwin Type "help", "copyright", "credits" or "license" for more inform...
X Description: Bug report Bug description: Python 3.16.0a0 (heads/main:09117bc, Sep 6 2026, 15:04:05) [Clang 21.0.0 (clang-2100.1.1.101)] on darwin Type "help", "copyright", "credits"...
Opengraph URL: https://github.com/python/cpython/issues/157048
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Failed BytesIO reinitialization mutates the stream's position and contents","articleBody":"# Bug report\n\n### Bug description:\n\n```pycon\nPython 3.16.0a0 (heads/main:09117bc, Sep 6 2026, 15:04:05) [Clang 21.0.0 (clang-2100.1.1.101)] on darwin\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import io\n...\n... stream = io.BytesIO(b\"abcd\")\n... stream.seek(2)\n... view = stream.getbuffer()\n... try:\n... stream.__init__(b\"replacement\")\n... except BufferError:\n... pass\n... print(stream.tell(), stream.getvalue(), bytes(view))\n... # 0 b'' b'abcd'\n... view.release()\n...\n0 b'' b'abcd'\n```\n\nThis is happening because the implementation of `BytesIO.__init__` resets state before checking for the `BufferError`:\n\nhttps://github.com/python/cpython/blob/09117bc3173b6854f3d614fb0efe79bca4b4cc63/Modules/_io/bytesio.c#L1129-L1137\n\n\n### CPython versions tested on:\n\n3.16, CPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-157049\n* gh-157068\n* gh-157069\n* gh-157070\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/ngoldbaum","@type":"Person","name":"ngoldbaum"},"datePublished":"2026-09-06T21:19:01Z","url":"https://github.com/python/cpython/issues/157048"}
| 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 | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d253433f-1d40-effa-c404-5407890901c4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B938:21DFED:34A2B0:42BB6E:6B01FA49 |
| html-safe-nonce | 4660cc215f2c3486a60ce0c298d4cc785277cd196cc7e6c958128436a606be21 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTM4OjIxREZFRDozNEEyQjA6NDJCQjZFOjZCMDFGQTQ5IiwidmlzaXRvcl9pZCI6IjU5OTk3Mjk0NjIxMzUwOTM4MzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4c1f765ac25c454cda4639409503d96692be0c0acd943fc699d987d5b455e4be |
| hovercard-subject-tag | issue:5367717441 |
| 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/157048/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9937741d769e7963a9476c61e2db89f7edcbe0f7c40480049c22b74338513e30/python/cpython/issues/157048 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9937741d769e7963a9476c61e2db89f7edcbe0f7c40480049c22b74338513e30/python/cpython/issues/157048 |
| og:image:alt | Bug report Bug description: Python 3.16.0a0 (heads/main:09117bc, Sep 6 2026, 15:04:05) [Clang 21.0.0 (clang-2100.1.1.101)] on darwin Type "help", "copyright", "credits" or "license" for more inform... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ngoldbaum |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width