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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:56:53+00:00 2026-06-03T02:56:53+00:00

What is the method-wrapper type in Python 3? If I define a class like

  • 0

What is the method-wrapper type in Python 3? If I define a class like so:

class Foo(object):
    def __init__(self, val):
        self.val = val
    def __eq__(self, other):
        return self.val == other.val

And then do:

Foo(42).__eq__

I get:

<bound method Foo.__eq__ of <__main__.Foo object at 0x10121d0>>

But if I do (in Python 3 ):

Foo(42).__ne__

I get:

<method-wrapper '__ne__' of Foo object at 0x1073e50>

What is a “method-wrapper” type?

Edit: sorry to be more accurate: class method-wrapper is the type of __ne__, as if I do:

>>> type(Foo(42).__ne__)
<class 'method-wrapper'>

Whereas the type of __eq__ is:

>>> type(Foo(42).__eq__)
<class 'method'>

Furthermore method-wrapper seems to be the type of any undefined magic method on a class (so __le__, __repr__, __str__ etc if not explicitly defined will also have this type).

What I am interested in is how the method-wrapper class is used by Python. Are all “default implementations” of methods on a class just instances of this type?

  • 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-03T02:56:54+00:00Added an answer on June 3, 2026 at 2:56 am

    This is because ‘unbound methods’ don’t exist in Python 3.

    In Python 3000, the concept of unbound methods has been removed, and the expression “A.spam” returns a plain function object. It turned out that the restriction that the first argument had to be an instance of A was rarely helpful in diagnosing problems, and frequently an obstacle to advanced usages — some have called it “duck typing self” which seems an appropriate name.
    (Source)

    In Python 2.x, we had bound methods and unbound methods. A bound method was bound to an object, meaning that when it was called, it passed the object instance as the first variable (self, normally). An unbound method was one where the function was a method, but without a instance it belonged to – it would throw an error if something other than an object instance was passed in to the method.

    Now, in 3.x, this has been changed. Instead of bound/unbound methods, when you request a method of an object, it returns the function object, but wrapped in a wrapper function that passes the instance variable in. This way there is no need to make a distinction between bound and unbound methods – bound methods are wrapped, unbound are not.

    To clarify the difference:

    2.x:

    a = A()
    f = A.method # f is an unbound method - you must pass an instance of `A` in to it as the first argument.
    f = a.method # f is a bound method, bound to the instance `a`.
    

    3.x:

    a = A()
    f = A.method # f is a function
    f = a.method # f is a wrapped function with it's first argument filled with `a`.
    

    a.method can be thought of as:

    def method-wrapper():
        A.method(a)
    

    For more on this, check out Guido’s blog – the history of Python.

    Edit:

    So, the reason this all applies is that, here, __ne__() has not been overridden – it’s at a default state, which is an identity check, implemented in C (line 980ish). The wrapper is there to provide the method with the above functionality.

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

Sidebar

Related Questions

I'd like to write a simple wrapper for the python list type that forces
I'd like to create a Python class decorator (*) that would be able to
public class A { public void test(Integer i) { System.out.println(In Wrapper Method); } public
The DataContext.GetTable() method will return an object of type: System.Data.Linq.Table By doing that, I
I'd like a pointer wrapper class that acts just like a raw pointer but
My query is, can a getter method ever return a wrapper data type? Will
I'm trying to write a wrapper class for a protected method which I wish
I've created a wrapper function for jQuery's $.ajax() method so I can pass different
The intention is to build a wrapper to provide a consistent method of calling
I have: @Component class MyDecorator{ private Cache cache; /* some wrapped methods like get

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.