On Wed, Feb 10, 2021 at 11:58 PM Anders Munch email@example.com wrote:
On Wed, Feb 10, 2021 at 1:46 AM Anders Munch firstname.lastname@example.org wrote:
How about swapping around "locale" and None?
Inada Naoki email@example.com wrote:
I thought it, but it may not work. Consider about function like this:
def read_text(self, encoding=None): with open(self._filename, encoding=encoding) as f: return f.read()
If `encoding=None` suppresses the warning, functions like this never warned.
I don't see why they should be. The author clearly knew about the encoding argument to open, they clearly intended for a None value to be given in some cases, and at the time of writing None meant to use a locale-dependent encoding.
It is not clear. The author may just want to "use the default encoding same to open()". If so, the caller of the function should be warned. To warn caller, this function can use `encoding=io.text_encoding(encoding)` as described in the PEP.
We are not discussing about changing default encoding for now.
The section "Prepare to change the default encoding to UTF-8" gave me the impression that this was meant as a stepping stone on the way to doing just that. If that was not the intention, my apologies for the misread.
This *can* be stepping stone. But it is not a frist goal. This PEP doesn't discourange omitting encoding option anytime soon when user really need to use locale encoding.
Default encoding is used for:
a. Really need to use locale specific encoding b. UTF-8 (bug. not work on Windows) c. ASCII (not a bug, but slow on Windows)
I assume most usages are (b) and (c). This PEP can reduce them soon.
If we decided to change the default encoding in the future, we need to warn omitting encoding option. Reducing (b) and (c) will reduce the total warning shown in the future. This is what "Prepare" means.
Additionally, `encoding="locale"` will be backward/forward compatible way to use locale-specific encoding when we decided to change the default encoding. So this PEP can be a very important stepping stone.
On the other hand, it is not a problem that we can not use `encoding="locale"` in backward-compatible code *for now*. Python 3.9 become EOL in 2025. We won't emit warning for the default encoding until then.
People can use `encoding="locale"` after they drop Python 3.9 support. No problem.