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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:26:55+00:00 2026-05-25T13:26:55+00:00

One can do something like this: class master: @combomethod def foo(param): param.bar() # Param

  • 0

One can do something like this:

class master:
    @combomethod 
    def foo(param):
        param.bar() # Param could be type as well as object

class slaveClass( master ):
    @classmethod 
    def bar(cls):
        print("This is class method")

slaveType = slaveClass
slaveType.foo()

class slaveInstance( master ):
    def __init__(self, data):
        self.data = data
    def bar(self):
        print("This is "+self.data+" method")


slaveType = slaveInstance("instance")
slaveType.foo()

combomethod is defined in “Creating a method that is simultaneously an instance and class method“.

My question is, why is it like this, that default first parameter can’t be used as parameter of comboclass? Or at least, why can’t I pass object to classmethod as the first parameter? I know the difference between classmethod and instancemethods, and I know decorators, but I might not understand how built-in @classmethod and self parameter passing is made. Is there a technical limitation? Or, why isn’t combomethod allready built in?

  • 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-25T13:26:55+00:00Added an answer on May 25, 2026 at 1:26 pm

    combomethod doesn’t create a method object when accessed but a specially wrapped function. Like methods each access creates a new object, in this case a new function object.

    class A:
        def __init__(self):
            self.data = 'instance'
    
        @combomethod 
        def foo(param):
            if isinstance(param, A):
                print("This is an " + param.data + " method.")
            elif param is A:
                print("This is a class method.")
    
    >>> a = A()
    >>> A.foo
    <function foo at 0x00CFE810>
    >>> a.foo
    <function foo at 0x00CFE858>
    
    >>> A.foo()
    This is a class method.
    >>> a.foo()
    This is an instance method.
    

    It’s new for each access:

    >>> A.foo is A.foo
    False
    >>> a.foo is a.foo
    False
    

    foo is really _wrapper in disguise:

    >>> A.foo.__code__.co_name
    '_wrapper'
    

    When called from a class the closure has obj == None (note that ‘self’ here refers to the combomethod, which has a reference to the original function object in self.method):

    >>> print(*zip(A.foo.__code__.co_freevars, A.foo.__closure__), sep='\n')
    ('obj', <cell at 0x011983F0: NoneType object at 0x1E1DF8F4>)
    ('self', <cell at 0x01198530: combomethod object at 0x00D29630>)
    ('objtype', <cell at 0x00D29D10: type object at 0x01196858>)
    

    When called as the attribute of an instance, obj is the instance:

    >>> print(*zip(a.foo.__code__.co_freevars, a.foo.__closure__), sep='\n')
    ('obj', <cell at 0x01198570: A object at 0x00D29FD0>)
    ('self', <cell at 0x01198530: combomethod object at 0x00D29630>)
    ('objtype', <cell at 0x00D29D10: type object at 0x01196858>)
    

    Here is the original function stored in the combomethod:

    >>> A.foo.__closure__[1].cell_contents.method
    <function foo at 0x00D1CB70>
    >>> A.foo.__closure__[1].cell_contents.method.__code__.co_name
    'foo'
    

    _wrapper executes self.method with either the class or instance as the first argument given the value of obj:

    if obj is not None:
        return self.method(obj, *args, **kwargs)
    else:
        return self.method(objtype, *args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In bash one can escape arguments that contain whitespace. foo a string This also
How is it that tools like this one can make an ajax style call
Say I have a class Code defined like this, with a user specified type
My table schema is something like this 1. Master table : Clause Columns ClauseID
In the Modern Objective-C runtime, you can do something like this: @interface MyClass :
In C++0x, I can do something like this: double f(double x) { return x;
I know that new-ing something in one module and delete-ing it in another can
Where one can learn more about VectorScript (the Pascal-like programming languaged built into NNA
I understand that one can raise an event in the class that the implementation
Using the WCF web programming model one can specify an operation contract like so:

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.