Opened 7 years ago

Closed 7 years ago

#6700 closed (wontfix)

smart_decorator util

Reported by: SmileyChris Owned by: SmileyChris
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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)

smart_decorator.diff (3.9 KB) - added by SmileyChris 7 years ago.

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by SmileyChris

comment:1 Changed 7 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to SmileyChris
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 7 years ago by mtredinnick

  • Resolution set to wontfix
  • Status changed from assigned to closed

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.

Note: See TracTickets for help on using tickets.
Back to Top