Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3337974
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:19:07+00:00 2026-05-18T00:19:07+00:00

Given a list of decorator methods, how would one apply those to a callable?

  • 0

Given a list of decorator methods, how would one apply those to a callable?

For example, since:

@foo
@bar
def baz():
    pass

…is the same as:

def baz():
    pass
baz = foo(bar(baz)))

…one would assume that with a list of decorators ([foo, bar]) they could be applied to baz dynamically.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:19:07+00:00Added an answer on May 18, 2026 at 12:19 am

    With yet another decorator!

    def yad(decorators):
        def decorator(f):
            for d in reversed(decorators):
                f = d(f)
            return f
        return decorator
    

    example usage

     list_of_decorators = [foo, bar]
    
    @yad(list_of_decorators)
    def foo():
        print 'foo'
    

    Without the decorator syntax, it would look like

     func = yad(list_of_decorators)(func)
    

    If you wanted to apply the same list to multiple functions, you can do it like:

     dec = yad(list_of_decorators)
    
     func1 = dec(func1)
    
     @dec
     def func2():
         pass
    

    As recursive points out in the comments, you can define yad (I’m sure there’s a better name for this) to accept *decorators instead of decorators. Then you don’t have to use brackets if you’re creating the list in situ. The way that I’ve demonstrated is better if the list is created elsewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a list ["foo", "bar", "baz"] and an item in the list "bar" ,
Given a list, how would I select a new list, containing a slice of
Given a list of urls, I would like to check that each url: Returns
Given a list of locations such as <td>El Cerrito, CA</td> <td>Corvallis, OR</td> <td>Morganton, NC</td>
Given a list of sets: S_1 : [ 1, 2, 3, 4 ] S_2
Given a List<T> in c# is there a way to extend it (within its
Given a list of strings, I want to sort it alphabetically and remove duplicates.
Given a list of objects, I am needing to transform it into a dataset
Given a list of arrays and lots of setup time I need to quickly
Problem: Given a list of strings, find the substring which, if subtracted from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.