On Wed, Feb 10, 2021 at 1:46 AM Anders Munch <a...@flonidan.dk> wrote:
>
>
> Inada Naoki  <songofaca...@gmail.com> wrote:
> > This warning is opt-in warning like BytesWarning.
>
> What use is a warning that no-one sees?

At least, I see.
We can fix stdlib and tests first, and fix some major tools too.

After that, `encoding="locale"` becomes backward/forward compatible at
some point.

> When the default is switched to encoding="utf8", it will break software, and 
> people need to be warned of that.
> UnicodeDecodeError's will abound when files that used to be read in a 
> single-byte encoding fails to decode as utf-8. All it takes is a single é.
> If the default encoding is ever to change, there's no way around a noisy 
> warning.
>

Please read the PEP and some my posts in this threads.
We are not discussing about changing default encoding for now.

This PEP provides a tool to find missing `encoding="utf-8"` bug for now.
The goal of the PEP is encourage `encoding="utf-8"` when the user
assumes encoding is UTF-8.

If we decide to change the default encoding. EncodingWarning can be
used to discourage omitting the `encoding` option.
But it is out of scope of the PEP. We don't discourage omitting
encoding option in Python 3.10.


> How about swapping around "locale" and None?  That is, make "locale" the new 
> default that emits a warning, and encoding=None emits no warning.  That has 
> the advantage that old code can be updated to say encoding=None, and then it 
> will work on both old and new Pythons without warning.
>

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.

So I think current PEP is better.
If users want to use locale encoding, they don't need to fix the
warning anytime soon. They can wait to drop Python 3.9 support.
If they want to fix all warnings soon, they can
`encoding=locale.getpreferredencoding(False)`.

Regards,
-- 
Inada Naoki  <songofaca...@gmail.com>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/4Q74PW673RMBMQTDZXHTVE6X7FT6DSAL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to