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

error message is misleading when executing await on non-async func #125511

Closed
sandeep-gh opened this issue Oct 15, 2024 · 2 comments
Closed

error message is misleading when executing await on non-async func #125511

sandeep-gh opened this issue Oct 15, 2024 · 2 comments

Comments

@sandeep-gh
Copy link

sandeep-gh commented Oct 15, 2024

Bug report

Bug description:

 def wrapper(afunc):
    async def hook(arg):
        arg = arg + 1
        return await afunc(arg)
    return hook


# bug missing async keyword
def afunc(arg):
    print(f"afunc called with arg = {arg}")
    pass

callback_func = wrapper(afunc)

import asyncio
asyncio.run(callback_func(5))

The error message is:
TypeError: object NoneType can't be used in 'await' expression

The object is of type function , just not async function.

CPython versions tested on:

3.11

Operating systems tested on:

Other

@sandeep-gh sandeep-gh added the type-bug An unexpected behavior, bug, or error label Oct 15, 2024
@YvesDup
Copy link
Contributor

YvesDup commented Oct 15, 2024

Hi @sandeep-gh, your code could be reduce to:

async def main():
    await afunc(5)

asyncio.run(main())

Where afunc is a function (not a coroutine), which return None. And await None raise a TypeError exception.
So there is no bug here, just an exception raised.

@picnixz
Copy link
Contributor

picnixz commented Oct 15, 2024

I agree (though AFAICT it should be afunc(6) but that's besides the point). I'm closing it as a non-CPython issue. More precisely, if you were to unroll the construction, callback_func would be equivalent to:

async def callback_func(x):
	x = x + 1
	z = afunc(x)  # your 'afunc' returns None
	t = await z   # await None raises normally
	return t

@picnixz picnixz closed this as not planned Won't fix, can't repro, duplicate, stale Oct 15, 2024
@picnixz picnixz removed the type-bug An unexpected behavior, bug, or error label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants