top | item 3807784

Show HN: zodiac, a new approach to monkey patching in python

39 points| colinmarc | 14 years ago |github.com | reply

11 comments

order
[+] yyyt|14 years ago|reply
I can't see how this is different from mock.py. Mock can also do temporary patching:

with patch('path.to.object') as my_mock: my_mock.method.return_value = ...

also you can patch a module/class with a function.

[+] halayli|14 years ago|reply
I'd avoid monkey patching, it can confuse the programmer as to which module is being used. In a small program it's not a big deal but in large systems it can become an issue.
[+] colinmarc|14 years ago|reply
It makes sense in certain situations. For example, if you're using non-blocking i/o with an event loop (using gevent or similar) then as soon as you have one blocking operation, performance suffers dramatically.

Monkeypatching gevent's socket globally allows you to use libraries and drivers like pymongo off the shelf, and they will be non-blocking by default.

[+] almost|14 years ago|reply
I think it's generally accepted that monkey patching is a Really Bad Idea but sometimes it's the least bad option available.
[+] njharman|14 years ago|reply
I'd avoid making it "easy". Easy being defined as "usable by easily confused programmers who don't understand it or the trade offs."
[+] devy|14 years ago|reply
Can we say this is very un-pythonic?