-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Closed
Labels
py-coreRelates to py/ directory in sourceRelates to py/ directory in source
Description
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
Labels
py-coreRelates to py/ directory in sourceRelates to py/ directory in source