Advertisement
rfmonk

functools_update_wrapper.py

Jan 15th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import functools
  5.  
  6.  
  7. def myfunc(a, b=2):
  8.     """docstring for myfunc()."""
  9.     print ' called myfunc with:', (a, b)
  10.     return
  11.  
  12.  
  13. def show_details(name, f):
  14.     """Show details of a callable object."""
  15.     print '%s:' % name
  16.     print ' object:', f
  17.     print ' __name__:',
  18.     try:
  19.         print f.__name__
  20.     except AttributeError:
  21.         print ' (no __name__)'
  22.     print ' __doc__', repr(f.__doc__)
  23.     print
  24.     return
  25.  
  26. show_details('myfunc', myfunc)
  27.  
  28. p1 = functools.partial(myfunc, b=4)
  29. show_details('raw wrapper', p1)
  30.  
  31. print 'Updating wrapper:'
  32. print ' assign:', functools.WRAPPER_ASSIGNMENTS
  33. print ' update:', functools.WRAPPER_UPDATES
  34. print
  35.  
  36. functools.update_wrapper(p1, myfunc)
  37. show_details('updated wrapper', p1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement