toggling decorators

后端 未结 7 1853
伪装坚强ぢ
伪装坚强ぢ 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:41

    another straight way:

    # mymodule.py
    from deco import benchmark
    
    class foo(object):
    
      def f():
        # code
    
      if :
        f = benchmark(f)
    
      def g():
        # more code
    
      if :
        g = benchmark(g)
    

提交回复
热议问题