classification
Title: Differentiate decorator and decorator factory in docs
Type: enhancement Stage: needs patch
Components: Documentation Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: adelfino, chris.jerdonek, docs@python, eric.araujo, ezio.melotti, fdrake, ncoghlan
Priority: normal Keywords: easy

Created on 2012-07-27 19:10 by eric.araujo, last changed 2018-06-18 14:16 by adelfino.

Messages (6)
msg166600 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-07-27 19:10
Some of the confusion encountered when writing decorators arise from the difference between a decorator (@something) and a decorator factory (@something(args)).  It would help to adopt this clearer terminology in our docs: a decorator takes the decorated function as argument and does its business, a decorator factory takes some arguments and returns a decorator which wraps the decorated function.

(I think it was Nick who suggested this in a recent-ish mailing list thread.)
msg176138 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-22 23:20
The tutorial doesn't seem to mention decorators, do you think this should be covered there?
FWIW while explaining decorators I usually use 3 examples:
 1) a simple decorator that accepts a function, does something, and returns the same function;
 2) a decorator that defines and returns an inner function;
 3) a decorator factory, that defines two nested inner functions

Not sure if it's necessary to include the first example though.
msg176149 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-11-23 02:52
No, using decorators needs to be in the tutorial, but writing your own is a metaprogramming task that's beyond the tutorial's scope.

A HOWTO guide would be appropriate, though.
msg319882 - (view) Author: Andrés Delfino (adelfino) * Date: 2018-06-18 13:32
If deemed appropriate, I can take the task of writing a HOWTO for decorators/decorators factories.
msg319884 - (view) Author: Fred L. Drake, Jr. (fdrake) (Python committer) Date: 2018-06-18 13:46
I like Éric's terminology; giving a concrete name to the concept makes it a lot easier to grasp, and this doesn't require inventing any new component terms.

Andrés, if you'd like to tackle this, that's great!  I'd be happy to for you to bounce drafts through me if you like.
msg319885 - (view) Author: Andrés Delfino (adelfino) * Date: 2018-06-18 14:16
Alright! :D Yes, your help will definitely come in handy, thanks!
History
Date User Action Args
2018-06-18 14:16:06adelfinosetmessages: + msg319885
2018-06-18 13:46:07fdrakesetnosy: + fdrake
messages: + msg319884
2018-06-18 13:32:33adelfinosetnosy: + adelfino
messages: + msg319882
2012-11-23 02:52:13ncoghlansetmessages: + msg176149
2012-11-22 23:20:48ezio.melottisetmessages: + msg176138
2012-11-22 23:06:48ezio.melottisetnosy: + chris.jerdonek
2012-11-09 15:04:15ezio.melottisetversions: + Python 3.4
nosy: + ezio.melotti

keywords: + easy
type: enhancement
stage: needs patch
2012-07-27 19:10:07eric.araujocreate