#25269: Method decorator should accept a iterable of decorators
-------------------------------+--------------------
     Reporter:  zauddelig      |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Uncategorized  |    Version:  1.8
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  1
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 Hello,
 The new method decorator allow to decorate a class directly. to augment
 its readability I would propose to let it accept an iterable of decorator
 functions.

 This could be useful because it's common to decorate views using redundant
 sets of decorators inside the same project or subproject, one could argue
 that the same result is attained creating a new decorator or a Mixin, yet
 an iterable, i. e.  a tuple,  seem to me more plastic and maintainable
 than a class or a function.

 This could be also useful if one intend to dynamically decorate
 dynamically created classes although this is most probably going to be
 useful in less than the 1% of the cases, so actually not significant.

 The proposal introduces a polymorphic behaviour to `method_decorator`
 which should now accept both function and iterables, so both the following
 examples should be valid:

 {{{
 decorators = (
     blacklist_ip,
     request_is_cool,
     login_required,
 )

 @method_decorator(decorators,"dispatch")
 class ProtectedView(View):
     # lot of meaningful code
     pass

 @method_decorator(login_required, "dispatch")
 class LessProtectedView(View):
     # lot of meaningful code
     pass
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25269>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.ffef03170c95e7fd13100ee6bd63d01d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to