| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
This is perhaps the most minimal fix, however, there's an alternative version that would be more invasive. Some observations:
|
Sorry, something went wrong.
| for obj in objs: | ||
| json.dump(obj, outfile, **dump_args) | ||
| outfile.write('\n') | ||
| if infile is not sys.stdin: |
There was a problem hiding this comment.
This should be a finally I think. If there is an exception happening in json.dumps for instance, we would have it left open. So this should be moved after the except ValueError as e with some finally.
Sorry, something went wrong.
There was a problem hiding this comment.
I tried looking at the git history of this file and it's a bit tricky to understand why it's not using content managers. At one point it did have context manager approach, then it was migrated to manually calling of open.
If there's a friction point, it's the "in place" feature. I don't think the in place feature/requirement ever fundamentally worked for the json lines case.
Sorry, something went wrong.
| if options.json_lines: | ||
| objs = (json.loads(line) for line in infile) | ||
| else: | ||
| objs = (json.load(infile),) |
There was a problem hiding this comment.
This one can fail directl, so please be careful that we close the infile beforehand (that's the reaason why we have the try-finally in the first place).
Sorry, something went wrong.
There was a problem hiding this comment.
We're probably using a generator here to save memory. Otherwise we could've just used a list comprehension.
Sorry, something went wrong.
There was a problem hiding this comment.
My comment was about the else branch. It's not a generator, it's a regular tuple.
Sorry, something went wrong.
|
The only test that is failing for me locally is the test_writing_in_place. The "in place" functionality is a bit surprising and doesn't really have clear requirements around error handling. It's a bit disconcerting that in the "in place" mode you can overwrite/delete the original file if there's an error. |
Sorry, something went wrong.
|
Closed in favour of #132632, thanks anyway! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.