On Wed, Sep 16, 2020 at 12:59 AM Rob Cliffe via Python-ideas <python-ideas@python.org> wrote:
On 14/09/2020 17:36, Christopher Barker wrote:
 
nstructions that are not part of the JSON spec) but the proposed new functions will be strict.

as it looks like I maybe the one to write the PR -- no, I'm not suggesting any changes to compliance.

The only thing even remotely on the table is only supporting UTF-8 -- but IIUC, the current functions, if they do the encoding/decoding for you, are already UTF-8 only, so no change.

load() and dump() work with text file-like objects -- they are not doing any encoding/decoding.

loads() is working with strings or bytes. if strings, then no encoding. if bytes, then:

"The ``encoding`` argument is ignored and deprecated since Python 3.1"

which I figured meant utf-8 but it fact it seems to work with utf-16 as well.

In [17]: utf16 = '{"this": 5}'.encode('utf-16')                                                    

In [18]: json.loads(utf16)                                                                        
Out[18]: {'this': 5}

which surprises me. I'll need to look at the code and see what it's doing. Unless someone wants to tell us :-)

dumps(), meanwhile, dumps a str, so gain, no encoding.

The idea here is that if you want to use loadf() or dumpf(), it will be utf-8, and if you want to use another encoding, you can open the file yourself and use load() or dump()
 
To minimise possible confusion, I think that the documentation (both the docstrings and the online docs) should be *very clear* about this.

Yes, and they need some help in that regard now anyway.

-CHB

 
E.g.
loads:
    ...
    loads accepts blah-blah-blah.  This is different from loadf which only accepts strict JSON.

loadf:
    ...
    loadf only accepts strict JSON.  This is different from loads which blah-blah-blah

Etc.
Rob Cliffe
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/ABQKK6GSK33I2XBJK4VK4RUEUAQ3HDVV/
Code of Conduct: http://python.org/psf/codeofconduct/


--
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython