Title: `bytes.translate()` returns short inputs starting with NUL untranslated · Issue #158334 · python/cpython · GitHub
Open Graph Title: `bytes.translate()` returns short inputs starting with NUL untranslated · Issue #158334 · python/cpython
X Title: `bytes.translate()` returns short inputs starting with NUL untranslated · Issue #158334 · python/cpython
Description: Bug description: On main, bytes.translate() returns its input untranslated when the input is shorter than 256 bytes, its first bytes (up to eight) are NUL, and the remaining bytes map to themselves: t = bytes.maketrans(b'\x00', b'Z') pri...
Open Graph Description: Bug description: On main, bytes.translate() returns its input untranslated when the input is shorter than 256 bytes, its first bytes (up to eight) are NUL, and the remaining bytes map to themselves...
X Description: Bug description: On main, bytes.translate() returns its input untranslated when the input is shorter than 256 bytes, its first bytes (up to eight) are NUL, and the remaining bytes map to themselves...
Opengraph URL: https://github.com/python/cpython/issues/158334
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`bytes.translate()` returns short inputs starting with NUL untranslated","articleBody":"### Bug description:\n\nOn main, `bytes.translate()` returns its input untranslated when the input is shorter than 256 bytes, its first bytes (up to eight) are NUL, and the remaining bytes map to themselves:\n\n```python\nt = bytes.maketrans(b'\\x00', b'Z')\nprint(b'\\x00'.translate(t))\nprint(b'\\x00\\x00'.translate(t))\nprint((b'\\x00' * 300).translate(t)[:2])\n```\n\nOutput on main:\n\n```\nb'\\x00'\nb'\\x00\\x00'\nb'ZZ'\n```\n\nPython 3.14 prints `b'Z'`, `b'ZZ'` and `b'ZZ'`. This started with GH-157346 (gh-155742), which moved the `PyBytesWriter_Finish()` call in `bytes_translate_impl()` before the `memcmp()` that decides whether to return the original object.\n\nExpected: `b'Z'` and `b'ZZ'`.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-158335\n* gh-158344\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/fedonman","@type":"Person","name":"fedonman"},"datePublished":"2026-09-28T11:34:35Z","url":"https://github.com/python/cpython/issues/158334"}
| 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:b4f048ff-18f2-7704-8588-5b14c9b9900d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D756:240CD1:36F4CF1:45E0D95:6B01EDFD |
| html-safe-nonce | 4923649fa7e5b1436d18bdacafe37fd6f287cd40033787487b21f54419c6d1d1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzU2OjI0MENEMTozNkY0Q0YxOjQ1RTBEOTU6NkIwMUVERkQiLCJ2aXNpdG9yX2lkIjoiNzgzMDkzNjE4OTUxODYwNTgyMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3a670b273bc0bee19262ac8cee7c1e9a4c4760d3c9b1114da67d2d4b1f9f40b8 |
| hovercard-subject-tag | issue:5613855724 |
| 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/158334/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0a50e6e7934ab69ead341778acf64886b5e95456c877fa79d3ddf6727211c9fe/python/cpython/issues/158334 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0a50e6e7934ab69ead341778acf64886b5e95456c877fa79d3ddf6727211c9fe/python/cpython/issues/158334 |
| og:image:alt | Bug description: On main, bytes.translate() returns its input untranslated when the input is shorter than 256 bytes, its first bytes (up to eight) are NUL, and the remaining bytes map to themselves... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fedonman |
| 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