3 ms·
Dry-run can be implemented succinctly in Python with a function decorator wrapping those functions that should run conditionally. Nice aspects of this techniq
by aranchelk 5y ago
Dry-run can be implemented succinctly in Python with a function decorator wrapping those functions that should run conditionally.
Nice aspects of this technique:
Inside the decorator you have access to both the function’s name and its arguments so you can print descriptive messages to the user e.g. “In dry run, would have run function ‘delete’ on ‘/foo/bar’”
You can use the name of the decorator as de facto documentation, e.g. “@destructive”