ookPython-version-sensitive monkeypatching | |
Download |
ook Ranking & Summary
Advertisement
- License:
- GPL v3
- Price:
- FREE
- Publisher Name:
- Zero Piraeus
- Publisher web site:
- https://bitbucket.org/schesis/
ook Tags
ook Description
ook is a simple Python library to assist with monkeypatching Python methods and functions on a per-Python-version basis. It provides one decorator, patch, which conditionally patches callables depending on which version of Python is running.ExampleThis one's used in ook's test suite:import itertoolsfrom ook import patch@patch(itertools, 2.5)def combinations(iterable, r): # From . pool = tuple(iterable) n = len(pool) if r > n: return indices = range(r) yield tuple(pool for i in indices) while True: for i in reversed(range(r)): if indices != i + n - r: break else: return indices += 1 for j in range(i+1, r): indices = indices + 1 yield tuple(pool for i in indices)Usagepatch accepts an arbitrary number of version arguments, in a variety of formats:@patch(some.module.or.class, 2.5, "2.6.8", (2, 7, 3), 3)def method_or_function(signature): """Do something.""" pass... as well as min and max keyword arguments:@patch(some.module.or.class, min="2.5.4", max=2.7)def method_or_function(signature): """Do something.""" pass... which can be combined:@patch(some.module.or.class, "3.1.5", max=3.1)def method_or_function(signature): """Do something.""" passNote: If you specify both keyword and non-keyword version arguments, the patch will only take effect if both the explicitly specified versions and the implied version ranges are satisfied.With no arguments other than the module or class to be patched, patch applies the patch regardless of Python version:@patch(some.module.or.class)def method_or_function(signature): """Do something, no matter what.""" passInstallationThis should do the trick:pip install ookProduct's homepage
ook Related Software