Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iscoroutinefunction doesn't work for partial bound methods #95444

Closed
pdewacht opened this issue Jul 29, 2022 · 4 comments
Closed

iscoroutinefunction doesn't work for partial bound methods #95444

pdewacht opened this issue Jul 29, 2022 · 4 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@pdewacht
Copy link

pdewacht commented Jul 29, 2022

Bug report

iscoroutinefunction doesn't work for partial bound methods. Consider this example. The second assert fails.

import asyncio
import functools

class A:
    async def a(self, x, y):
        pass

assert asyncio.iscoroutinefunction(A().a)
assert asyncio.iscoroutinefunction(functools.partial(A().a, 1))

I found two related issues:

Your environment

  • CPython versions tested on: Python 3.10.5
  • Operating system and architecture: Debian unstable, amd64
@pdewacht pdewacht added the type-bug An unexpected behavior, bug, or error label Jul 29, 2022
@PurityLake
Copy link
Contributor

This seems to be fixed in #67707

Can confirm assertion passes on main branch. Python version3.12.0a0.

@corona10
Copy link
Member

This seems to be fixed in #67707

Yeah I double check that this issue was already fixed.

@graingert
Copy link
Contributor

That's weird

@graingert
Copy link
Contributor

graingert commented Jul 30, 2022

Ah that's because the the parital of a bound method isn't going via while ismethod(f):, it passes inspect._signature_is_functionlike directly

>>> import functools
>>> class A:
...     async def a(self, x, y):
...         pass
... 
>>> A().a
<bound method A.a of <__main__.A object at 0x7f8219707a30>>
>>> import inspect
>>> inspect._signature_is_functionlike(A().a)
True
>>> A().a.__code__.co_flags
195
>>> 
>>> p = functools.partial(A().a)
>>> inspect.ismethod(p)
False
>>> m = functools._unwrap_partial(p)
>>> m
<bound method A.a of <__main__.A object at 0x7f8219707a30>>
>>> inspect.isfunction(m)
False
>>> inspect._signature_is_functionlike(m)
True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants