Title: Update FileIO comments, documentation to match implementation · Issue #129011 · python/cpython · GitHub
Open Graph Title: Update FileIO comments, documentation to match implementation · Issue #129011 · python/cpython
X Title: Update FileIO comments, documentation to match implementation · Issue #129011 · python/cpython
Description: Documentation Discuss thread: https://discuss.python.org/t/change-open-write-to-guarantee-all-bytes-will-be-written-or-an-exception-will-be-thrown/71082 FileIO behaves differently than its code comments around read and readall. Update th...
Open Graph Description: Documentation Discuss thread: https://discuss.python.org/t/change-open-write-to-guarantee-all-bytes-will-be-written-or-an-exception-will-be-thrown/71082 FileIO behaves differently than its code com...
X Description: Documentation Discuss thread: https://discuss.python.org/t/change-open-write-to-guarantee-all-bytes-will-be-written-or-an-exception-will-be-thrown/71082 FileIO behaves differently than its code com...
Opengraph URL: https://github.com/python/cpython/issues/129011
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Update FileIO comments, documentation to match implementation","articleBody":"# Documentation\n\nDiscuss thread: https://discuss.python.org/t/change-open-write-to-guarantee-all-bytes-will-be-written-or-an-exception-will-be-thrown/71082\n\n1. FileIO behaves differently than its code comments around `read` and `readall`. Update the code comments to match current behavior\n - [PEP 475](https://peps.python.org/pep-0475/), reads are retried in some cases\n - `.readall()` makes multiple system calls by design\n3. Add documentation to [`open()` builtin](https://docs.python.org/3.14/library/functions.html#open) that `buffering=0`, which currently just says \"disables buffering\") changes how `.write()` behaves and may result in data loss as a result of a partial write (ex. gh-126606).\n - `TextIO` and `BufferedIO` (which are gotten via commonly used `open('README.rst')`, `open('README.rst', 'rb')`) retry partial writes providing a user a guarantee either all bytes will be written or an exception will be thrown.\n - `FileIO` is \"Raw I/O\" and by [PEP-3116](https://peps.python.org/pep-3116/#raw-i-o) design, as documented, and currently implemented does not retry partial writes. \n - Most the time, `buffering=0` currently speeds up writing a file, but it can also result in corrupted files, ex. gh-126606 from using FileIO directly\n - I would like to try and change the behavior of `buffering=0` to use BufferedIO but with a 0 sized buffer, and that is on my roadmap but will be a while (people use the flag for a reason / get benefit!). This will mean `open()` always returns an object which implements \"Write all or throw exception\" behavior.\n - Add warning / document existing behavior on `open()` in the meantime.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-129012\n* gh-135328\n* gh-150957\n* gh-150958\n* gh-150959\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/cmaloney","@type":"Person","name":"cmaloney"},"datePublished":"2025-01-19T01:19:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/129011/cpython/issues/129011"}
| 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:a1a84ed6-67b1-b594-f0f2-48fb823db1d4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C19A:3AC145:3706:4976:6A521B83 |
| html-safe-nonce | 7216cad7652d8d34caee08c9ab8fd97f329c39ae58f002dba82ce945c34b9e70 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTlBOjNBQzE0NTozNzA2OjQ5NzY6NkE1MjFCODMiLCJ2aXNpdG9yX2lkIjoiNzY5MDc0ODM0MTAwMTUyNjE0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6cce81c28b72fe385ebfb276dc09c0b21f935e3513579644e23dc3fa26823aea |
| hovercard-subject-tag | issue:2797330399 |
| 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/129011/issue_layout |
| twitter:image | https://opengraph.githubassets.com/497c2a35d4968e1bc04fce15443e87dc962bb4d23b5476388a6124800dc0285c/python/cpython/issues/129011 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/497c2a35d4968e1bc04fce15443e87dc962bb4d23b5476388a6124800dc0285c/python/cpython/issues/129011 |
| og:image:alt | Documentation Discuss thread: https://discuss.python.org/t/change-open-write-to-guarantee-all-bytes-will-be-written-or-an-exception-will-be-thrown/71082 FileIO behaves differently than its code com... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cmaloney |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width