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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:21:01+00:00 2026-05-17T01:21:01+00:00

Python decorators are fun to use, but I appear to have hit a wall

  • 0

Python decorators are fun to use, but I appear to have hit a wall due to the way arguments are passed to decorators. Here I have a decorator defined as part of a base class (the decorator will access class members hence it will require the self parameter).

class SubSystem(object):
    def UpdateGUI(self, fun): #function decorator
        def wrapper(*args):
            self.updateGUIField(*args)
            return fun(*args)
        return wrapper

    def updateGUIField(self, name, value):
        if name in self.gui:
            if type(self.gui[name]) == System.Windows.Controls.CheckBox:
                self.gui[name].IsChecked = value #update checkbox on ui 
            elif type(self.gui[name]) == System.Windows.Controls.Slider:
                self.gui[name].Value = value # update slider on ui 

        ...

I’ve omitted the rest of the implementation. Now this class is a base class for various SubSystems that will inherit from it – some of the inherited classes will need to use the UpdateGUI decorator.

class DO(SubSystem):
    def getport(self, port):
        """Returns the value of Digital Output port "port"."""
        pass

    @SubSystem.UpdateGUI
    def setport(self, port, value):
        """Sets the value of Digital Output port "port"."""
        pass

Once again I have omitted the function implementations as they are not relevant.

In short the problem is that while I can access the decorator defined in the base class from the inherited class by specifiying it as SubSystem.UpdateGUI, I ultimately get this TypeError when trying to use it:

unbound method UpdateGUI() must be called with SubSystem instance as first argument (got function instance instead)

This is because I have no immediately identifiable way of passing the self parameter to the decorator!

Is there a way to do this? Or have I reached the limits of the current decorator implementation in Python?

  • 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-17T01:21:01+00:00Added an answer on May 17, 2026 at 1:21 am

    You need to make UpdateGUI a @classmethod, and make your wrapper aware of self. A working example:

    class X(object):
        @classmethod
        def foo(cls, fun):
            def wrapper(self, *args, **kwargs):
                self.write(*args, **kwargs)
                return fun(self, *args, **kwargs)
            return wrapper
    
        def write(self, *args, **kwargs):
            print(args, kwargs)
    
    class Y(X):
        @X.foo
        def bar(self, x):
            print("x:", x)
    
    Y().bar(3)
    # prints:
    #   (3,) {}
    #   x: 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to combine two decorators into one new decorator in python?
I am new to python decorators. I have understood the basic concepts with the
I don't know if Nested python decorator? is the right way to state this
Python beginner here, I have a list of lists and want to refer to
When creating decorators for use on class methods, I'm having trouble when the decorator
Here is a scenario, i hope you can help me with. I have python
I have recently stated trying to use the newer style of classes in Python
What is the difference between Python decorators and the decorator pattern? When should I
I'm trying to use decorators in order to manage the way users may or
In Python, I can use decorators to trace the function call, its variables and

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.