Skip to content

Differentiate decorator and decorator factory in docs #59679

Closed

Description

@merwok
BPO 15474
Nosy @freddrake, @rhettinger, @ncoghlan, @ezio-melotti, @merwok, @cjerdonek, @andresdelfino, @Windsooon, @dorosch

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-02-27.01:07:04.238>
created_at = <Date 2012-07-27.19:10:07.128>
labels = ['easy', '3.7', '3.8', '3.9', 'type-feature', 'docs']
title = 'Differentiate decorator and decorator factory in docs'
updated_at = <Date 2020-02-27.01:07:04.232>
user = 'https://github.com/merwok'

bugs.python.org fields:

activity = <Date 2020-02-27.01:07:04.232>
actor = 'rhettinger'
assignee = 'docs@python'
closed = True
closed_date = <Date 2020-02-27.01:07:04.238>
closer = 'rhettinger'
components = ['Documentation']
creation = <Date 2012-07-27.19:10:07.128>
creator = 'eric.araujo'
dependencies = []
files = []
hgrepos = []
issue_num = 15474
keywords = ['easy']
message_count = 13.0
messages = ['166600', '176138', '176149', '319882', '319884', '319885', '344512', '344539', '344644', '344653', '362568', '362758', '362760']
nosy_count = 10.0
nosy_names = ['fdrake', 'rhettinger', 'ncoghlan', 'ezio.melotti', 'eric.araujo', 'chris.jerdonek', 'docs@python', 'adelfino', 'Windson Yang', 'dorosch']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue15474'
versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

Activity

  1. merwok commented on Jul 27, 2012

    @merwok
    MemberAuthor

    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.)

  2. ezio-melotti commented on Nov 22, 2012

    @ezio-melotti
    Member

    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.

  3. ncoghlan commented on Nov 23, 2012

    @ncoghlan
    Contributor

    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.

  4. andresdelfino commented on Jun 18, 2018

    @andresdelfino
    Contributor

    If deemed appropriate, I can take the task of writing a HOWTO for decorators/decorators factories.

  5. freddrake commented on Jun 18, 2018

    @freddrake
    Member

    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.

  6. andresdelfino commented on Jun 18, 2018

    @andresdelfino
    Contributor

    Alright! :D Yes, your help will definitely come in handy, thanks!

  7. Windsooon commented on Jun 4, 2019

    Windsooonmannequin
    Mannequin

    Hi, Andrés Delfino. Are you still working on it?

  8. andresdelfino commented on Jun 4, 2019

    @andresdelfino
    Contributor

    Hi Windson Yang! Yes, I'm still working on it. I'll have it ready by the end of June.

  9. ezio-melotti commented on Jun 4, 2019

    @ezio-melotti
    Member

    If you want some early feedback I believe you can already create a PR and mark it as work-in-progress/don't-merge.

    If you need some material you can find the slides of a talk about decorators that I did at
    https://www.pycon.it/media/conference/slides/understanding-decorators.pdf
    Feel free to take from it whatever you need :)

  10. andresdelfino commented on Jun 4, 2019

    @andresdelfino
    Contributor

    Great! I'll definitely give it a look.

    I prefer not to make a PR until everything is in its place. You can check the status though:

    https://github.com/andresdelfino/cpython/tree/decorators-howto

    Fred was very helpful with his insight :)

  11. dorosch commented on Feb 24, 2020

    doroschmannequin
    Mannequin

    Hi, Andrés Delfino. Are you still working on it? I could help with this issues.

  12. andresdelfino commented on Feb 27, 2020

    @andresdelfino
    Contributor

    Hi, no I'm no longer working on this.

  13. rhettinger commented on Feb 27, 2020

    @rhettinger
    Contributor

    Thanks Andrés.

    I'm going to close this one as it has been open for a long time and not attracted interest. Also, in practice this ambiguity doesn't seem to be an issue and people almost universally refer to anything usable with the @-notation as a decorator. Further, it has become common for tooling such as @lru_cache and @DataClass to be usable both with and without arguments, so the distinction no longer makes sense in some cases.

  14. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions