toggling decorators

后端 未结 7 1850
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 18:37

What\'s the best way to toggle decorators on and off, without actually going to each decoration and commenting it out? Say you have a benchmarking decorator:



        
7条回答
  •  别那么骄傲
    2021-01-04 18:54

    You could add the conditional to the decorator itself:

    def benchmark(func):
        if not :
            return func
        def decorator():
        # fancy benchmarking 
        return decorator
    

提交回复
热议问题