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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:50:38+00:00 2026-06-05T17:50:38+00:00

I find the following example mildly surprising: >>> class Foo: def blah(self): pass >>>

  • 0

I find the following example mildly surprising:

>>> class Foo:
        def blah(self):
            pass


>>> f = Foo()
>>> def bar(self):
        pass

>>> Foo.bar = bar
>>> f.bar
<bound method Foo.bar of <__main__.Foo object at 0x02D18FB0>>

I expected the bound method to be associated with each particular instance, and to be placed in it at construction. It seems logical that the bound method would have to be different for each instance, so that it knows which instance to pass in to the underlying function – and, indeed:

>>> g = Foo()
>>> g.blah is f.blah
False

But my understanding of the process is clearly flawed, since I would not expect assigning a function into a class attribute would put it in instances that had already been created by then.

So, my question is two fold –

  1. Why does assigning a function into a class apply retroactively to instances? What are the actual lookup rules and processes that make this so?
  2. Is this something guaranteed by the language, or just something that happens to happen?
  • 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-05T17:50:40+00:00Added an answer on June 5, 2026 at 5:50 pm

    You want to blow your mind, try this:

    f.blah is f.blah
    

    That’s right, the instance method wrapper is different each time you access it.

    In fact an instance method is a descriptor. In other words, f.blah is actually:

    Foo.blah.__get__(f, type(f))
    

    Methods are not actually stored on the instance; they are stored on the class, and a method wrapper is generated on the fly to bind the method to the instance.

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

Sidebar

Related Questions

Consider the following example: class Base(models.Model): myfield = models.CharField() class Derived(Base): pass Now, the
I want to scale images these day and find the following example: Example #1
In the following example, MySQL fails to use to find a ref for the
for example i use following command to find a record SELECT `users`.`mail` FROM `users`
how to find greatest 2 numbers out of 3 numbers. like in following example.
If you have a templated base class as in the following example: class A{
I was surprised to find that the following example code only updates a single
In the case of the following example, I can not easily find the places
Given the following example domains: class UserRole implements Serializable { User user Role role
Consider the following example: #include Python.h #include <boost/python.hpp> #include <boost/shared_ptr.hpp> class A {}; class

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.