Skip to content

Bound methods that are the same are not equal (CPython incompatibility) #5233

@kevinkk525

Description

@kevinkk525

Sorry for not being able to be more specific in the issue description, suggestions welcome.

The coroutine of an object changes its identity every time it gets accessed:

class C:
    async def test(self):
        pass

>>> c=C()
>>> c.test==c.test
False
>>> a=c.test
>>> b=c.test
>>> a==b
False
>>> getattr(c,"test")
<bound_method 7f4067c383c0 <C object at 7f4067c37920>.<generator>>
>>> getattr(c,"test")
<bound_method 7f4067c38400 <C object at 7f4067c37920>.<generator>>
>>> getattr(c,"test")
<bound_method 7f4067c384c0 <C object at 7f4067c37920>.<generator>>

Therefore there is no way of storing a link to the coroutine and later comparing if the stored link actually belongs to the courotine of that class.

In Cpython this of course works:

class C:
    async def test(self):
        pass

>>> c=C()
>>> a=c.test
>>> b=c.test
>>> a==b
True
>>> c.test==c.test
True
>>> 

When comparing the coroutines of a class then it works correctly:

>>> C.test==C.test
True
>>> a=C.test
>>> b=C.test
>>> a==b
True

With coroutines outside of classes it does work too:

async def test():
...     pass
>>> a=test
>>> b=test
>>> a==b
True
>>> test==test

Is this behaviour fixable or a victim of optimizations and resource savings?

Metadata

Metadata

Assignees

No one assigned

    Labels

    py-coreRelates to py/ directory in source

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy