On Wed, Feb 10, 2021 at 11:58 PM Anders Munch <a...@flonidan.dk> wrote:
>
> On Wed, Feb 10, 2021 at 1:46 AM Anders Munch <a...@flonidan.dk> wrote:
> >> How about swapping around "locale" and None?
> Inada Naoki  <songofaca...@gmail.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.

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/DBDI5FEJCF2IOTSAS7VELO27MNEQMK2Z/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to