[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Antoine Pitrou
On Fri, 07 Aug 2020 08:54:37 - "Kazantcev Andrey" wrote: > Chris Angelico wrote: > > Why do you want dump and load to take parameters from "somewhere > > else"? > > Because developers of libraries don't think about configuring json.dump > method in mos of cases. Then you should report a

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Serhiy Storchaka
06.08.20 11:03, Kazantcev Andrey пише: > JSON serialization used in many different libraries without the ability for > configuration (Example > https://github.com/aio-libs/aioredis/blob/8a207609b7f8a33e74c7c8130d97186e78cc0052/aioredis/commands/pubsub.py#L18). > Propose to add something like the

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Marco Sulla
What about __json__()? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/arch

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Kazantcev Andrey
Chris Angelico wrote: > Why do you want dump and load to take parameters from "somewhere > else"? Because developers of libraries don't think about configuring json.dump method in mos of cases. I would like to have a mechanism that would allow tweaking the behaviour for the entire program. I ju

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Paul Moore
On Fri, 7 Aug 2020 at 09:26, Kazantcev Andrey wrote: > > The problem in this code > > lib.py > ``` > from json import dumps > > def some_func(): > # do something > res = dumps(...) > # do something > ``` > > I wish dump and load themselves could take parameters from somewhere else, >

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Chris Angelico
On Fri, Aug 7, 2020 at 6:24 PM Kazantcev Andrey wrote: > > The problem in this code > > lib.py > ``` > from json import dumps > > def some_func(): > # do something > res = dumps(...) > # do something > ``` > > If I patch dumps like you propose lib doesn't see any change. Also, it's all

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Kazantcev Andrey
The problem in this code lib.py ``` from json import dumps def some_func(): # do something res = dumps(...) # do something ``` If I patch dumps like you propose lib doesn't see any change. Also, it's all hacks. I wish dump and load themselves could take parameters from somewhere el

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Chris Angelico
On Fri, Aug 7, 2020 at 5:50 PM Kazantcev Andrey wrote: > > Chris Angelico wrote: > > > Not gonna be 100% reliable and I don't think it belongs in the stdlib, > > but might be useful. > > That is the problem. Sometimes libs import only methods. I don't see that often, do you have a specific exampl

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Kazantcev Andrey
Chris Angelico wrote: > Not gonna be 100% reliable and I don't think it belongs in the stdlib, > but might be useful. That is the problem. Sometimes libs import only methods. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send a

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread Chris Angelico
On Fri, Aug 7, 2020 at 5:22 PM Kazantcev Andrey wrote: > > 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 js

[Python-ideas] Re: Propouse add context to json module.

2020-08-07 Thread 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. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to p

[Python-ideas] Re: Propouse add context to json module.

2020-08-06 Thread Antoine Pitrou
I agree with Raymond. The "implicit context" pattern is really only desirable in a small subset of situations, and I don't think configuring JSON serialization is one of those. (it may even be an active nuisance, because some libraries may be using JSON as an implementation detail and a "JSON c

[Python-ideas] Re: Propouse add context to json module.

2020-08-06 Thread raymond . hettinger
Based on experience with the decimal module, I think this would open a can of worms. To match what decimal does, we would need a Context() object with methods for dump, dumps, load, loads. There would need to be a thread-local or contextvar instance accessed by getcontext and setcontext, and p