* owner: nobody => adurdin
* status: new => assigned
* easy: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: assigned => new
* owner: adurdin => nobody
* has_patch: 0 => 1
Comment:
Implemented lukeplant's suggestion of `method_decorator_with_args`.
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:7>
* needs_better_patch: 0 => 1
Comment:
I'm not terribly happy with the `..with_args` suffix (same for
`decorator_from_middleware_with_args`). It feels weird to having to
remember to different function names that do basically the same.
Especially for decorators that take arguments optionally I'd appreciate if
the `method_decorator` function would simply allow me to pass the
arguments for the decorator optionally, too. E.g.::
{{{
@method_decorator(permission_required, 'spam.more_eggs',
another_arg=True)
def method(self, whatever):
# bla
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:8>
* stage: Accepted => Design decision needed
Comment:
After talking to adurdin on IRC more about it, I realized that this ticket
shows why the "generate a method decorator" pattern is aweful. Marking as
DDN.
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:9>
Comment (by lukeplant):
@jezdez: My experience with decorators tells me that confusing decorators
and decorator factories is always a bad idea, despite the temptation of
convenience. If you look at the
[http://code.djangoproject.com/browser/django/trunk/django/views/decorators/cache.py#L7
cache_page] decorator, you'll find probably some of the nastiest code in
Django, and it was caused by this confusion. You always end up with
isinstance checks and horrible little edge cases, and it makes it hard to
reason about the code, since it can accept/return fundamentally different
types of things.
However, in this case, this code:
{{{
#!python
@method_decorator(permission_required, 'spam.more_eggs',
another_arg=True)
def method(self, whatever):
}}}
is no improvement over this code:
{{{
#!python
@method_decorator(permission_required('spam.more_eggs',
another_arg=True))
def method(self, whatever):
}}}
in terms of the original motivation of this ticket, and it violates
TOOWTDI.
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:10>
* component: Core (Other) => Utilities
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:12>
* stage: Design decision needed => Accepted
Comment:
I grudgingly acknowledge the opportunity of adding
`method_decorator_with_args`, for consistency with
`decorator_from_middleware_with_args`.
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:13>
* status: new => assigned
* owner: nobody => susan
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:14>
Comment (by susan):
Applied the attached patch and all the tests pass.
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:15>
* cc: douglas.russell@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:16>
* status: assigned => new
* owner: susan =>
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:17>
* cc: toracle@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/13879#comment:18>