Skip to content

Instantly share code, notes, and snippets.

@nedbat
Created October 21, 2018 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nedbat/d603a34136299f0c0b8e442fccadeb7d to your computer and use it in GitHub Desktop.
Save nedbat/d603a34136299f0c0b8e442fccadeb7d to your computer and use it in GitHub Desktop.
Decorator tracing comparison

Decorator tracing comparison

dec0.py

1  def decorator(f):
2      return f
3  
4  @decorator
5  def func():
6      print("hello")
7  
8  func()
3.7 3.8 3.8 (pr9731)

dec1.py

1  def decorator(arg):
2      def _dec(f):
3          return f
4      return _dec
5  
6  @decorator(6)
7  def my_function():
8      x = 13
9  

10 my_function()

3.7 3.8 3.8 (pr9731)

dec2.py

1  def decorator1(f):
2      return f
3  
4  def decorator2(f):
5      return f
6  
7  def decorator3(f):
8      return f
9  

10 @decorator1 11 @decorator2 12 @decorator3 13 def func(): 14 print("hello") 15 16 func()

3.7 3.8 3.8 (pr9731)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment