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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:38:25+00:00 2026-06-17T22:38:25+00:00

How can you get a not bound class method? class Foo: @classmethod def bar(cls):

  • 0

How can you get a not bound class method?

class Foo:
    @classmethod
    def bar(cls): pass

>>> Foo.bar
<bound method type.bar of <class '__main__.Foo'>>

Edit: This is python 3. Sorry for the confusion.

  • 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-17T22:38:26+00:00Added an answer on June 17, 2026 at 10:38 pm

    Python 3 does not have unbound methods. Forget about classmethods for a moment, and look at this:

    >>> class Foo:
    ...     def baz(self): pass
    >>> Foo.baz
    <function __main__.baz>
    

    In 2.x, this would be <unbound method Foo.baz>, but 3.x does not have unbound methods.

    If you want to get the function out of a bound method, that’s easy:

    >>> foo = Foo()
    >>> foo.baz
    <bound method Foo.baz of <__main__.Foo object at 0x104da6850>>
    >>> foo.baz.__func__
    <function __main__.baz>
    

    In the same way:

    >>> class Foo:
    ...     @classmethod
    ...     def bar(cls): pass
    >>> Foo.bar
    <bound method type.bar of <class '__main__.Foo'>>
    >>> Foo.bar.__func__
    <function __main__.bar>
    

    Things are much more interesting in 2.x, because there actually are unbound methods to get. You can’t normally see an unbound classmethod, because the whole point is that they get bound to the class at class creation time, instead of being left unbound and then bound to each instance at instance creation time.

    But really, an unbound method is just any instancemethod whose im_self is None. So, just as you can do this:

    class Foo(object):
        def baz(self): pass
    
    foo = Foo()
    bound_baz = foo.baz
    unbound_baz = new.instancemethod(bound_baz.im_func, None, bound_baz.im_class)
    

    Note that bound_baz.im_func is the 2.x version of bound_baz.__func__ in 3.x—but that new.instancemethod does not have a 3.x equivalent.

    The documentation says that new is deprecated in favor of types, for 3.x compatibility, and in fact, you can do this in 2.x:

    unbound_baz = types.MethodType(bound_baz.im_func, None, bound_baz.im_class)
    

    But that doesn’t work in 3.x, because MethodType does not take a class parameter, and does not allow its instance parameter to be None. And personally, when I’m doing something that is explicitly 2.x-only and cannot be ported to 3.x, I think using new is clearer.

    Anyway, given a class in 2.x, you can do this:

    class Foo(object):
        @classmethod
        def bar(cls): pass
    
    bound_bar = Foo.bar
    unbound_bar = new.instancemethod(bound_bar.im_func, None, bound_bar.im_class)
    

    If you print it out, you’ll see:

    <unbound method type.bar>
    

    Or, using your example, with an old-style class:

    class Foo:
        @classmethod
        def bar(cls): pass
    
    <unbound method classobj.bar>
    

    And yes, maybe it’s a bit of a cheat that the im_class of a classmethod for an old-style class is classobj even though that’s not Foo.__class__, but it seems like the most reasonable way to get old-style and new-style classes working similarly in all of the usual use cases.

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

Sidebar

Related Questions

I simply can not get Visual Studio 2005 to find the System.Configuration.ConfigurationManager class. Here
i use this method before 1 time. but Now i can not get video
When you decorate a method, it is not bound yet to the class, and
I can not get to make this comparison in this simple code error ..
I can not get logs from some customers, can I use Google Urchin in
I can not get environment at custom target shell. CMakeList.txt set( ENV{TEST_VAR} Hello )
I suppose this is not so hard but I can not get it. For
In silverlight, I can not get INotifyPropertyChanged to work like I want it to
I have a long label that spans multiple lines and I can not get
For the life of me, I can not get matplotlib to display graphs in

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.