pypy2 6.0.0 unbound method has type `method` not `instancemethod`

Issue #2847 resolved
Jeong YunWon created an issue

Code:

class A(object):

    def f(self):
        pass


print(A.f)
print(type(A.f))

Result of pypy2 6.0.0

$ python instancemethod.py
<unbound method A.f>
<type 'method'>
$ python --version
Python 2.7.13 (ab0b9caf307d, Apr 24 2018, 18:05:02)
[PyPy 6.0.0 with GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]

Expected result (of CPython 2.7.13)

$ python instancemethod.py      
<unbound method A.f>
<type 'instancemethod'>
$ python --version 
Python 2.7.13

Comments (5)

  1. Armin Rigo

    That issue is only about the name of the type itself: types.MethodType says <type 'instancemethod'> in CPython but <type 'method'> in PyPy.

  2. Jeong YunWon reporter

    Thanks for the fix. It seems the patch fixed the name instancemethod but I found another similar glitch.

    Here is more test code:

    class A(object):
    
        def f(self):
            pass
    
    
    print(A.f)
    print(type(A.f))
    print(type(A.__call__))
    print(type(object.__call__))
    
    assert type(A.f).__name__ == 'instancemethod'
    assert type(A.__call__).__name__ == 'method-wrapper'
    assert type(object.__call__).__name__ == 'method-wrapper'
    

    PyPy result:

    <unbound method A.f>
    <type 'method'>
    <type 'method'>
    <type 'method'>
    Traceback (most recent call last):
      File "instancemethod.py", line 13, in <module>
        assert type(A.f).__name__ == 'instancemethod'
    AssertionError
    

    CPython result:

    <unbound method A.f>
    <type 'instancemethod'>
    <type 'method-wrapper'>
    <type 'method-wrapper'>
    

    It seems PyPy2 is not distinguishing method-wrapper and instancemethod.

    I also found PyPy3 and PyPy2 have same behavior about the method-wrapper

    CPython3.6.2 result:

    <function A.f at 0x10ce14e18>
    <class 'function'>
    <class 'method-wrapper'>
    <class 'method-wrapper'>
    

    PyPy3.5-6.0.0 result

    <function A.f at 0x000000010dafad40>
    <class 'function'>
    <class 'method'>
    <class 'method'>
    
  3. Log in to comment