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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:17:47+00:00 2026-05-28T11:17:47+00:00

Having the following code, what can I do with the ‘foo’ function to make

  • 0

Having the following code, what can I do with the ‘foo’ function to make it unbound in any case even if it is assigned to class attribute? Overriding __get__ doesn’t help – as far as I understand because it is not used when function is absent from __dict__ of an instance (it is so in case of class attributes).
But what else can be done here?

def foo(x):
    print(x)

def foo_get(self, obj, type=None):
    return foo

foo.__get__ = foo_get

class A(object):
    def __init__(self):
        self.f = foo
class B(object):
    f = foo


a = A()

print(a.f)               #<function foo at 0x2321d10>
print(a.f.__get__(a, A)) #<function foo at 0x2321d10>

b = B()

print(b.f)               #<bound method B.foo of <__main__.B object at 0x23224d0>>
  • 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-28T11:17:47+00:00Added an answer on May 28, 2026 at 11:17 am

    I’m pretty sure you want @staticmethod.

    foo = staticmethod(foo)

    You can also define __get__ on a callable class:

    class Foo(object):
        def __get__(self, obj, type=None):
            return self
    
        def __call__(self, x):
            print(x)
    
    foo = Foo()
    
    class A(object):
        def __init__(self):
            self.f = foo
    class B(object):
        f = foo
    
    
    foo(1) # 1
    a = A()
    
    a.f(1) # 1
    print(a.f)               #<function foo at 0x2321d10>
    print(a.f.__get__(a, A)) #<function foo at 0x2321d10>
    
    b = B()
    b.f(1) # 1
    
    
    print(b.f)               #<__main__.Foo object at 0x7fa8c260be10>
    

    It’s one extra level of indentation and a few extra lines of code, but that’s how it can be done, if it’s important.

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

Sidebar

Related Questions

I m having the following code, however, I can see that the radio button
I'm having a problem with TRY...CATCH blocks. Can someone explain why the following code
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
I have the following code: Public Class Form1 Private Function Step1_Execute() As Boolean Return
I'm having a problem with the following code. As you can a TripDetailsController is
Consider the following code: abstract class Foo<T> where T : Foo<T>, new() { void
I'm having compile time trouble with the following code: template <typename T, template <class
i'm having a problem with Galleria. the following code: <script type=text/javascript> $(document).keypress(function(e) { switch(e.keyCode)
I'm having a devil of a time understanding references. Consider the following code: class
Having the following code, how can I have get receive a map, and return

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.