Plus we need some cleverness in this function to detect whether it's passed a function or whether it's being used as a decorator factory. `IPython.external.decorator` may be able to help with that.