On Sat, Sep 12, 2020 at 7:59 AM Guido van Rossum <guido@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 <songofacandy@gmail.com>