On Fri, Aug 7, 2020 at 6:24 PM Kazantcev Andrey <hec...@yandex.ru> 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 
> hacks. I wish dump and load themselves could take parameters from somewhere 
> else, and that was the standard behaviour.

PLEASE include context when you reply.

Yes, I'm aware that my original demo wouldn't work with this kind of
thing. But (1) does that actually happen? and (2) my second example
will work, as long as you do it before this library imports anything
from json.

Why do you want dump and load to take parameters from "somewhere
else"? As a general rule, it's better for them to get their parameters
entirely from, well, their parameters. What you're trying to do is
override someone else's code, and that basically means monkeypatching
the library, or monkeypatching the json module. Take your pick.

ChrisA
_______________________________________________
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/archives/list/python-ideas@python.org/message/CBDVULQMTFMROAZBUBX2ASK5M6RNGOIQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to