6 ms·
I would argue that python provides even simpler syntax to enable functionality like this. @experiment.with(new_function) def old_function() ...
by chronial 11y ago
I would argue that python provides even simpler syntax to enable functionality like this.
@experiment.with(new_function)
def old_function()
...
- shoyer 11y agoAgreed -- a decorator seems like a much cleaner way to handle this.
- msellout 11y agoA decorator must be applied to a function or class, whereas a context manager can wrap an arbitrary section of code. So, it depends on how you want the tool to be used. I don't think there's a clear best design.
- buttscicles 11y agoThis was my thought as well, and it's also a bit more awkward if your function signatures differ. Luckily they aren't mutually exclusive and it should be easy to implement a decorator version.