[issue45644] Make json.tool soak up input before opening output for writing
New submission from Chris Wesseling : json.tool is very cute and handy for making json readable. But rewriting a file in place requires tools like sponge (on POSIX) or a tmpfile, because $ python -m json.tool foo.json foo.json results in an empty foo.json. I propose soaking up the infile before opening the outfile for writing, to prevent that. Much like sort -o does, but without the explicit flag. The patch I have prepared changes no behaviours, other than preventing an empty file... (still I see this as an enhancement and not a bug fix) -- messages: 405182 nosy: CharString priority: normal severity: normal status: open title: Make json.tool soak up input before opening output for writing type: enhancement ___ Python tracker <https://bugs.python.org/issue45644> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45644] Make json.tool soak up input before opening output for writing
Change by Chris Wesseling : -- keywords: +patch pull_requests: +27532 stage: -> patch review pull_request: https://github.com/python/cpython/pull/29269 ___ Python tracker <https://bugs.python.org/issue45644> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45644] Make json.tool soak up input before opening output for writing
Change by Chris Wesseling : -- pull_requests: +27537 pull_request: https://github.com/python/cpython/pull/29273 ___ Python tracker <https://bugs.python.org/issue45644> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45664] resolve_bases() and new_class() do not work with type alias of a built-in type
Change by Chris Wesseling : -- nosy: +CharString nosy_count: 4.0 -> 5.0 pull_requests: +27569 pull_request: https://github.com/python/cpython/pull/29273 ___ Python tracker <https://bugs.python.org/issue45664> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45664] resolve_bases() and new_class() do not work with type alias of a built-in type
Change by Chris Wesseling : -- nosy: +CharString, CharString nosy_count: 4.0 -> 5.0 pull_requests: +27569, 27570 pull_request: https://github.com/python/cpython/pull/29273 ___ Python tracker <https://bugs.python.org/issue45664> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45664] resolve_bases() and new_class() do not work with type alias of a built-in type
Change by Chris Wesseling : -- pull_requests: +27577 pull_request: https://github.com/python/cpython/pull/29273 ___ Python tracker <https://bugs.python.org/issue45664> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45644] Make json.tool soak up input before opening output for writing
Chris Wesseling added the comment: @Remi I left the current behaviour for --json-lines untouched, on purpose. My reasoning was that the json-lines format is often seen in JSON streaming, and I didn't want to break the case where the input is an endless stream from stdin or a named pipe. And to keep the patch simple with minimal change to the exposed interface. Simplest fix for the case in this current code would be: iff infile equals outfile (minding their types), call list(objs) on the generator[1] to materialise it in one go. The only case where that would break would be when infile == outfile and is a named pipe, but I can't imagine why I would want to both read and write to the same FIFO, other than comedic effect. [1] https://github.com/python/cpython/blob/122ca4d73faba279a579aa2011fa34661ce537a2/Lib/json/tool.py#L65 -- ___ Python tracker <https://bugs.python.org/issue45644> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45644] Make json.tool soak up input before opening output for writing
Change by Chris Wesseling : -- pull_requests: +27729 pull_request: https://github.com/python/cpython/pull/29478 ___ Python tracker <https://bugs.python.org/issue45644> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33927] Allow json.tool to have identical infile and outfile
Change by Chris Wesseling : -- nosy: +CharString nosy_count: 6.0 -> 7.0 pull_requests: +27728 pull_request: https://github.com/python/cpython/pull/29478 ___ Python tracker <https://bugs.python.org/issue33927> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue45664] resolve_bases() and new_class() do not work with type alias of a built-in type
Change by Chris Wesseling : -- nosy: -CharString, CharString ___ Python tracker <https://bugs.python.org/issue45664> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com