I recently had the following problem: I am developing a numerical library in Python (called spuq ) that needs scipy in its kernel. Now one of the functions in scipy, called btdtri , had an error for a specific set of input parameters. However, this bug is now fixed in scipy version 0.9 according to scipy developers. So there is something like this in my code:
import scipy def foo(a, b, c): if scipy.__version__>=(0, 9): return btdtri(a, b, c) else: return my_fixed_btdtri(a, b, c)
This works, however, I don't really like mutating my code with bug fixes for third-party packages. I would prefer it to be contained in one module that implements a workaround, and all the rest of my modules automatically use the fixed module.
Now my question is: what would be the best practice for such cases in general? For instance. write my spuq.contrib.scipy and say there
from scipy import * if __version__ < (0, 9): btdtri = my_fixed_btdtri
and instead of importing scipy import spuq.contrib.scipy everywhere? I think it's hard and easy to forget (and probably sloppy and ugly). Maybe there is a way to "automatically connect" to download the package and change the scipy module directly so that every other package sees only the patch package? I think this problem is quite common, so there probably should be some “best practices”.
source share