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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:24:38+00:00 2026-06-08T21:24:38+00:00

This is an academic question, more than a practical one. I’m trying to delve

  • 0

This is an academic question, more than a practical one. I’m trying to delve into the foundations of Python, and I wonder: could I implement the staticmethod and classmethod decorators in pure Python if I wanted to?

For staticmethod maybe I could keep a reference to the original function and call it omitting the first argument?

For classmethod maybe I could keep a reference to the original function and call it passing the type of the first argument, rather than the argument itself? (How would I handle it being called directly on the class?)

Again, it’s not that I want to actually implement it in my programs; I want to learn how the language works from it. If it’s possible to do I would really appreciate code samples. If not, I would appreciate explanations why it can’t be done theoretically. Thanks!

Edit: Thanks for the answer and for the reference to the descriptor protocol! As a means to further extend my understanding of Python I’d like to ask two more things:

  • Could this be done without the descriptor protocol, for example by implementing the __ call __ special method in our classes?

  • Does the descriptor protocol work the same way in Python 2.7 and in Python 3.x?

Thanks again!

  • 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-08T21:24:40+00:00Added an answer on June 8, 2026 at 9:24 pm

    There are examples in the docs:

    class StaticMethod(object):
        "Emulate PyStaticMethod_Type() in Objects/funcobject.c"
    
        def __init__(self, f):
            self.f = f
    
        def __get__(self, obj, objtype=None):
            return self.f
    

    And:

    class ClassMethod(object):
        "Emulate PyClassMethod_Type() in Objects/funcobject.c"
    
        def __init__(self, f):
            self.f = f
    
        def __get__(self, obj, klass=None):
            if klass is None:
                klass = type(obj)
            def newfunc(*args):
                return self.f(klass, *args)
            return newfunc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of an academic inquiry than a practical question. Are there any
This is more of an academic question about performance than a realistic 'what should
I know this is a rather academic question, but I wonder how one would
This is a bit more of an academic question. Indeed I am preparing for
Somewhat of an academic question, but I ran into this while writing some unit
This is really more of an academic question, but where is this function defined?
This is kind of an academic question, so feel free to exit now. I've
This is really just sort of an academic question, I'm just curious to know
This may seem to be an academic question, but still I would be very
This question is mostly academic. I ask out of curiosity, not because this poses

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.