Use encoding option or binary mode for open()#9608
Use encoding option or binary mode for open()#9608uranusjr merged 2 commits intopypa:masterfrom methane:open-encoding
encoding option or binary mode for open()#9608Conversation
| if requested: | ||
| requested_path = os.path.join(dest_info_dir, 'REQUESTED') | ||
| with open(requested_path, "w"): | ||
| with open(requested_path, "wb"): |
There was a problem hiding this comment.
As this simply opens then closes (creating an empty file), this makes no real difference. I'm inclined to prefer not to use "b" because that implies the file is binary, and it isn't. But I don't really care much.
pathlib.touch might be better, now we don't have to worry about Python 2 compatibility.
There was a problem hiding this comment.
I prefer binary mode because creating TextIOWrapper is waste of time/memory and using locale-specific encoding is root of bugs.
But I respect your preference.
There was a problem hiding this comment.
That's a good point I hadn't considered.
Actually, I went looking to see what encoding the REQUESTED file should use. https://packaging.python.org/specifications/recording-installed-packages/ says it's tool-specific, and refers to PEP 376 which says it can be empty or contain a comment. So the content is essentially irrelevant, and binary mode therefore makes sense.
Let's use binary mode, and add a comment saying "Create an empty file (see PEP 376)", just to be clear that the encoding isn't relevant.
No description provided.