[issue45644] Make json.tool soak up input before opening output for writing

2022-01-18 Thread Inada Naoki


Change by Inada Naoki :


--
nosy: +methane
nosy_count: 4.0 -> 5.0
pull_requests: +28860
pull_request: https://github.com/python/cpython/pull/30659

___
Python tracker 

___
___
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

2021-11-08 Thread Chris Wesseling


Change by Chris Wesseling :


--
pull_requests: +27729
pull_request: https://github.com/python/cpython/pull/29478

___
Python tracker 

___
___
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

2021-11-08 Thread Chris Wesseling


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 

___
___
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

2021-11-07 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

The proposed path does not work for `python -m json.tool --json-lines test.json 
test.json`. There is also https://github.com/python/cpython/pull/7865 that aims 
to fix this bug but I did not have the time to get back to it.

--
nosy: +remi.lapeyre

___
Python tracker 

___
___
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

2021-11-06 Thread Łukasz Langa

Łukasz Langa  added the comment:

Thanks, Chris! ✨  ✨

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
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

2021-11-06 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset a932631890d148444e5f9b09f4b57305475d6386 by Miss Islington (bot) 
in branch '3.9':
bpo-45644:  Make json.tool read infile before writing to outfile (GH-29273) 
(GH-29446)
https://github.com/python/cpython/commit/a932631890d148444e5f9b09f4b57305475d6386


--

___
Python tracker 

___
___
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

2021-11-06 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 6603f6b5bdf0ed164bad4eb432619da2e95fb518 by Miss Islington (bot) 
in branch '3.10':
bpo-45644:  Make json.tool read infile before writing to outfile (GH-29273) 
(GH-29445)
https://github.com/python/cpython/commit/6603f6b5bdf0ed164bad4eb432619da2e95fb518


--

___
Python tracker 

___
___
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

2021-11-06 Thread miss-islington


Change by miss-islington :


--
pull_requests: +27700
pull_request: https://github.com/python/cpython/pull/29446

___
Python tracker 

___
___
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

2021-11-06 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 815dad42d53fc40a6dc057e067f4a8a885c3b858 by Chris Wesseling in 
branch 'main':
bpo-45644:  Make json.tool read infile before writing to outfile (GH-29273)
https://github.com/python/cpython/commit/815dad42d53fc40a6dc057e067f4a8a885c3b858


--

___
Python tracker 

___
___
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

2021-11-06 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 2.0 -> 3.0
pull_requests: +27699
pull_request: https://github.com/python/cpython/pull/29445

___
Python tracker 

___
___
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

2021-11-06 Thread Łukasz Langa

Łukasz Langa  added the comment:

This is arguably a bugfix since truncating the `infile` cannot be construed as 
a useful feature in any sense. Thus I'm inclined to backport this to 3.10.1 and 
3.9.9 too.

--
nosy: +lukasz.langa
type: enhancement -> behavior
versions: +Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

___
___
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

2021-10-28 Thread Chris Wesseling


Change by Chris Wesseling :


--
pull_requests: +27537
pull_request: https://github.com/python/cpython/pull/29273

___
Python tracker 

___
___
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

2021-10-28 Thread Chris Wesseling


Change by Chris Wesseling :


--
keywords: +patch
pull_requests: +27532
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/29269

___
Python tracker 

___
___
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

2021-10-28 Thread Chris Wesseling


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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com