On Sat, Sep 12, 2020 at 7:59 AM Guido van Rossum <gu...@python.org> wrote:
>
> What happened to "not every three-line function needs to be a built-in"? This 
> is *literally* a three-line function.

This is not only common two line idiom. It creates huge amount of
potential bugs.

```
with open("myfile.json") as f:
    data = json.load(f)

with open("myfile.json", "w") as f:
    json.dump(f, ensure_ascii=False)
```

Both two lines have bugs; they don't specify `encoding` [1]. It uses
locale encoding to read/write JSON although the JSON file must be
encoded in UTF-8.
The locale encoding is legacy encoding on Windows. It is very easy to
write "not work on Windows".

My PEP 597 [2] will help to find such bugs. But it warns only in dev
mode to avoid too noisy DeprecationWarning.
Huge amounts of DeprecationWarning make people dismiss DeprecationWarning.

So helper functions will save people from this kind of bugs too.

[1] In case of `json.load(f)`, we can use binary file instead.
[2] https://www.python.org/dev/peps/pep-0597/

Regards,

-- 
Inada Naoki  <songofaca...@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/X5GEMWMPBGQGXPQLBRKV7D7KHKC6ODOA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to