4 ms·
Agreed -- a decorator seems like a much cleaner way to handle this.
by shoyer 11y ago
Agreed -- 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.