#13879: method_decorator doesn't supports decorators with arguments
---------------------------------------------+------------------------------
          Reporter:  marinho                 |         Owner:  nobody           
      
            Status:  new                     |     Milestone:  1.3              
      
         Component:  Uncategorized           |       Version:  1.2              
      
        Resolution:                          |      Keywords:  sprintnov13, 
decorators
             Stage:  Design decision needed  |     Has_patch:  0                
      
        Needs_docs:  0                       |   Needs_tests:  0                
      
Needs_better_patch:  0                       |  
---------------------------------------------+------------------------------
Changes (by lrekucki):

 * cc: lrekucki (added)

Comment:

 IMHO, the goal here is to be able to write:
 {{{
 m_perm_required = method_decorator(permission_required) # do this once

 class A(View):
    @m_perm_required('spam.mores_spam') # use it later many times without
 repeating method_decorator
    def get(self, request, *args, **kwrgs):
      #...
 }}}

 The current implementation handles only decorators without arguments, so
 you can only write:
 {{{
    @method_decorator(permission_required('spam.more_eggs')
    def method(self, ...):
        #...
 }}}

 This is similar to diffrence between "decorator_from_middleware" and
 "decorator_from_middleware_with_args" and I think the right solution here
 is to provide a "method_decorator_with_args" function.

 PS. The OP is wrong that his implementation handles all cases - there is
 no universal pattern in Python for transforming decorators with and
 without arguments if you allow the first argument to be a callable (a
 class for example). It's probably a matter of taste, so you can just
 disregard this part of comment :)

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13879#comment:3>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to