Hello,

On Sat, 23 Jan 2021 19:04:08 +0900
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.
> 
> On the other hand, if we add `open_text()`:
> 
> * Replacing open with open_text is easier than adding `,
> encoding="utf-8"`.

How is it easier, if "open_text" exists only in imagination, while
encoding="utf-8" has been there all this time?

The only easier thing than adding 'encoding="utf-8"' would be:

1. Just go ahead and switch the default encoding to utf-8 right away.
2. For backward compatibility, add "python3 --backward-compatibility"
switch. Perhaps even tell users to use it straight in
the UnicodeDecodeError backtrace.

> * Teachers can teach to use `open_text` to open text files. Students
> can use "utf-8" by default without knowing about what encoding is.

Let's also add max_int(), min_int(), max_float(), min_float() builtins.
Teachers can teach that if you need to min ints, then to use min_int(),
if you need to min floats, then to use min_float(), and otherwise, use
min(). Bonus point: max_int(), min_int(), max_float(), min_float() are
all easier to annotate.

> So `open_text()` can provide better developer experience, without
> waiting 10 years.

Except that in 10 years, when the default encoding is finally changed,
open_text() is a useless function, which now needs to be deprecated and
all the fun process repeated again.


[]

-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
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/23HBISVYGAJ5G25ZPXDNLD4YZX2XXZAQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to