7 Aug
2020
7 Aug
'20
2:29 a.m.
On Fri, Aug 7, 2020 at 5:22 PM Kazantcev Andrey
Maybe use context as a context manager.
For example
``` with json.Context(ensure_ascii=False): json.dumps(...) ```
Implementation can be done via contextlib.
If all you want is a way to parameterize naive calls to json.dumps(), you could monkeypatch it. import json import contextlib @contextlib.contextmanager def monkeypatch_json(**defaults): orig = json.dumps try: def dumps(*a, **kw): return orig(*a, **{**defaults, **kw}) json.dumps = dumps yield finally: json.dumps = orig Not gonna be 100% reliable and I don't think it belongs in the stdlib, but might be useful. ChrisA