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

  • SEARCH
  • Home
  • 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 7753461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:04:13+00:00 2026-06-01T12:04:13+00:00

I am trying different things to understand Decorators and functions in Python. Is the

  • 0

I am trying different things to understand Decorators and functions in Python.
Is the below code correct way :

import math
def calculate_area(func):
    def area(a,b):
        return a+b
    return area

class Donut():
    def __init__(self, outer, inner):
        self.inner = inner
        self.outer = outer

    @calculate_area
    @staticmethod
    def area(self):
        outer, inner = self.radius, self.inner
        return Circle(outer).area() - Circle(inner).area()

Will “staticmenthod” decorator tells the built-in default metaclass type (the class of a class, cf. this question) to not create bound methods ?
is it possible to do :

Donut.area(4,5)
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
Donut.area(4,5)
TypeError: unbound method area() must be called with Donut instance as first argument      (got int instance instead)

Please help me in understanding bound methods and unbound methods and what it the impact of decorator on them.

  • 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-06-01T12:04:14+00:00Added an answer on June 1, 2026 at 12:04 pm

    just swap the @staticmethod with your decorator

    import math
    def calculate_area(func):
        def _area(a, b):
            return a + b
        return _area
    
    class Donut():
        def __init__(self, outer, inner):
            self.inner = inner
            self.outer = outer
    
        @staticmethod
        @calculate_area
        def area(cls):
            outer, inner = self.radius, self.inner
            return ""
    

    EDIT 1:

    python interpreter requires to add @staticmethod at before another decorators, because , before creating a class type ,its need to determines the class members and instance members.if your first decorator is anything else ,interpreter known this function as an instance member. see this

    EDIT 2:

    it’s recommended to use @classmethod instead @staticmethod, for more info see this

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

Sidebar

Related Questions

I am just learning Jquery templates and trying different things step by step. Now
I am trying to execute different things depending on what os the users iPhone
So I can understand things better, I'm trying to get away from calling the
I am currently trying to learn Javascript and understand that functions are one of
I am trying to understand the following things: When I make an EJB project
this is really stupid, but I been trying dozens of different things and I
For a long time I've been trying different languages to find the feature-set I
Third try at fixing this tonight - trying a different approach than before now.
Im trying to apply different background color to even and odd items in a
I am trying to add different styles within a textarea eg bold, different colors

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.