On Sat, Jan 23, 2021 at 9:04 PM Inada Naoki <songofaca...@gmail.com> wrote:
>
> On Sat, Jan 23, 2021 at 10:47 AM Chris Angelico <ros...@gmail.com> wrote:
> >
> >
> > Highly dubious. I'd rather focus on just moving to UTF-8 as the
> > default, rather than bringing in a new function - especially with such
> > a confusing name.
> >
> > What exactly are the blockers on making open(fn) use UTF-8 by default?
>
> Backward compatibility. That's what PEP 597 tries to solve.
>
> 1. Add optional warning for `open()` call without specifying
> `encoding` option. (PEP 597)
> 2. (Several years later) Make the warning default.
> 3. (Several years later) Change the default encoding.
>
> When (2) happens, users are forced to write `encoding="utf-8"` to
> suppress the warning.
>
> But note that the default encoding is "utf-8" already in (most) Linux
> including WSL, macOS, iOS, and Android.
> And Windows user can read ASCII text files without specifying
> `encoding` regardless default encoding is legacy codec or "utf-8".
> So adding `, encoding="utf-8"` everywhere `open()` is used might be tedious 
> job.

Okay, but this (a) has a good end goal, and (b) is only
backward-incompatible with its default - adding the encoding parameter
makes your code compatible with all versions of Python.

> On the other hand, if we add `open_text()`:
>
> * Replacing open with open_text is easier than adding `, encoding="utf-8"`.
> * Teachers can teach to use `open_text` to open text files. Students
> can use "utf-8" by default without knowing about what encoding is.
>
> So `open_text()` can provide better developer experience, without
> waiting 10 years.

But this has a far worse end goal - two open functions with subtly
incompatible defaults, and a big question of "why should I choose this
over that". And if you start using open_text, suddenly your code won't
work on older Pythons.

> > Can the proposals be written with that as the ultimate goal (even if
> > it's going to take X versions and multiple deprecation phases), rather
> > than aiming for a messy goal where people aren't sure which function
> > to use?
> >
>
> Ultimate goal is make the "utf-8" default. But I don't know when we
> can change it.
> So I focus on what we can do in near future (< 5 years, I hope).
>

Okay. If the goal is to make UTF-8 the default, may I request that PEP
597 say so, please? With a heading of "deprecation", it's not really
clear what its actual goal is.

>From the sound of things - and it's still possible I'm misreading PEP
597, my apologies if so - this open_text function wouldn't really
solve anything much, and the original goal of "change the default
encoding to UTF-8" is better served by 597.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/U6BL5RWB4OPDZNM3NEFO3UPPZEIVYKYZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to