Opened 17 years ago
Closed 17 years ago
#6700 closed (wontfix)
smart_decorator util
Reported by: | Chris Beaven | Owned by: | Chris Beaven |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django has some "decorators" which accept additional arguments. These decorators can't be called with Python 2.4 format (@decorator(*args)
).
This util provides a smart_decorator
which can be used to allow a decorator which accepts additional arguments to handle both @decorator
and @decorator(*args)
formats. It also means that these decorators can be made backwards compatible too, which is always nice.
Attachments (1)
Change History (3)
by , 17 years ago
Attachment: | smart_decorator.diff added |
---|
comment:1 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
I don't think this is worth it. Code like this has uses sometimes, but, in general, it's just an extra layer of complexity that people have to understand when trying to debug this stuff. If there are specific cases that really need this sort of handling, then we can fix them with a couple of lines of code as we've done in login_required (and I'd much prefer to see sticking to keyword args there, rather than positional parameters as it rules out the chance of confusion).
In general, if a decorator takes parameters, it should always be called in one way. Historically, we have a couple of cases where that rule is broken in Django and have chosen to work around them, rather than break everybody's code, but it's not worth encouraging it in general. It's usually poor style (polymorphous function calls are generally confusing because you have to work out which signature is being applied) and make maintenance harder.