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 167023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:12:04+00:00 2026-05-11T12:12:04+00:00

I want to construct classes for use as decorators with the following principles intact:

  • 0

I want to construct classes for use as decorators with the following principles intact:

  1. It should be possible to stack multiple such class decorators on top off 1 function.
  2. The resulting function name pointer should be indistinguishable from the same function without a decorator, save maybe for just which type/class it is.
  3. Ordering off the decorators should not be relevant unless actually mandated by the decorators. Ie. independent decorators could be applied in any order.

This is for a Django project, and the specific case I am working on now the method needs 2 decorators, and to appear as a normal python function:

@AccessCheck @AutoTemplate def view(request, item_id) {} 

@AutoTemplate changes the function so that instead of returning a HttpResponse, it just returns a dictionary for use in the context. A RequestContext is used, and the template name is inferred from the method name and module.

@AccessCheck adds additional checks on the user based on the item_id.

I am guessing it’s just to get the constructor right and copy the appropriate attributes, but which attributes are these?

The following decorator won’t work as I describe:

class NullDecl (object):     def __init__ (self, func):         self.func = func     def __call__ (self, * args):         return self.func (*args) 

As demonstrated by the following code:

@NullDecl @NullDecl def decorated():     pass  def pure():     pass  # results in set(['func_closure', 'func_dict', '__get__', 'func_name', # 'func_defaults', '__name__', 'func_code', 'func_doc', 'func_globals']) print set(dir(pure)) - set(dir(decorated)); 

Additionally, try and add ‘print func.name‘ in the NullDecl constructor, and it will work for the first decorator, but not the second – as name will be missing.

Refined eduffy‘s answer a bit, and it seems to work pretty well:

class NullDecl (object):     def __init__ (self, func):         self.func = func         for n in set(dir(func)) - set(dir(self)):             setattr(self, n, getattr(func, n))      def __call__ (self, * args):         return self.func (*args)     def __repr__(self):         return self.func 
  • 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. 2026-05-11T12:12:05+00:00Added an answer on May 11, 2026 at 12:12 pm

    A do-nothing decorator class would look like this:

    class NullDecl (object):    def __init__ (self, func):       self.func = func       for name in set(dir(func)) - set(dir(self)):         setattr(self, name, getattr(func, name))     def __call__ (self, *args):       return self.func (*args) 

    And then you can apply it normally:

    @NullDecl def myFunc (x,y,z):    return (x+y)/z 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 259k
  • Answers 259k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Question1: Since maxSdkVersion is not specified, the application should be… May 13, 2026 at 11:14 am
  • Editorial Team
    Editorial Team added an answer It's a query to get the People object that has… May 13, 2026 at 11:14 am
  • Editorial Team
    Editorial Team added an answer Based on the assumption that you can't change your three… May 13, 2026 at 11:14 am

Related Questions

What is the best way to share objects between other classes? For example; a
I have an abstract base class which acts as an interface. I have two
I'm trying to unit test a few .NET classes that (for good design reasons)
Abstract classes are described as being useful for a family of objects (e.g. could

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.