bpo-17852: Fixed the documentation about closing files - #23135
Conversation
I know, I'm sorry. I'm just tired of this "You should have expected this surprising behavior that is not documented!" victim-blaming. Multiple people told me that the old documentation was correct.
Thank you for saying that.
Fixing this bug would not prevent data loss, because the docs says that python can exit without calling is guaranteed to write to the disk. |
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
…ssmann/cpython into documentation_of_open
Suggestion from methane Co-authored-by: Inada Naoki <songofacandy@gmail.com>
methane
left a comment
There was a problem hiding this comment.
LGTM. But wait a week for another core dev review.
When will "another core dev review" happen? |
No one knows. I thought if someone find this and want to review. But it was not happened in two weeks. |
|
Thanks @Volker-Weissmann for the PR, and @methane for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9. |
|
GH-23527 is a backport of this pull request to the 3.9 branch. |
Co-authored-by: Inada Naoki <songofacandy@gmail.com> (cherry picked from commit c8aaf71) Co-authored-by: Volker-Weissmann <39418860+Volker-Weissmann@users.noreply.github.com>
|
GH-23528 is a backport of this pull request to the 3.8 branch. |
Co-authored-by: Inada Naoki <songofacandy@gmail.com> (cherry picked from commit c8aaf71) Co-authored-by: Volker-Weissmann <39418860+Volker-Weissmann@users.noreply.github.com>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>

Most programming languages, including Python 2 call all the destructor of global variables if the program exists successfully.
Python 3 is not guaranteed to.
This can result in the arguments of file.write() not being written to the disk.
The guys in this issue also released this problem and discussed if it should be this way, but apparently all of them were completely brain-dead idiots because they did not check if the documentation of Python matches the actual behaviour. Instead, the documentation stated that Python will call f.close() (and I quote) "eventually", which is completely BS, because Python may never call f.close().
I can't fix the (imho stupid) behavior of Python 3 not calling destructors, but at least I can fix the documentation (this PR).
Especially for a programming language like Python, that is supposed to be used by people with limited CS knowledge, it is important that no features in the programming language yields surprising behavior and good documentation that is correct is also very important.
Excuse me for my language, but if one of the most popular programming languages doesn't manage to fix a simple but important documentation error within a year after someone reports it, it is a disgrace and failure of the open source model. If you support this kind of misleading documentation, you are 100 % responsible to every bug written by someone who thought that f.close() is called when the program exists. And they are 0 % responsible for the bug, because they trusted the documentation.
https://bugs.python.org/issue17852