4 ms·
In the Python codebases I work on, I always create a monkey.py in the repo root. With a comment warning against adding to it, but occasionally it’s the lesser e
by eloff 4y ago
In the Python codebases I work on, I always create a monkey.py in the repo root. With a comment warning against adding to it, but occasionally it’s the lesser evil.
A long time ago, when Django was less mature we had a monkey patch to add a join condition to some of our queries. It obviously broke when we needed to upgrade to Django 2, but it did allow us to eek out a major performance boost without abandoning the ORM quest builder. One of my coworkers practically fell over laughing when he discovered the file.
- kzrdude 4y agoSounds like you should add some conditionals so that one can easily monkeypatch the monkeypatching. `if django_patch_enable: import xyz; xyz.foo = 1`
- wisemanwillhear 4y agoI patched a Python Paramiko method to log all data immediately when it came over the wire for an automation library that ran a lot of our automated testing. It's hard to overstate how helpful this was when data seem to be missing. Once we overflowed an internal Paramiko buffer because it wasn't documented and we overlooked this possibility. The logging was important to pinning down the problem. The monkey patching was complex and ugly but ultimately worth it.