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

Incorrect type on .result() for a submitted async task results in invalid mypy suggestion #16819

Open
mthanded opened this issue Jan 22, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@mthanded
Copy link
Contributor

mthanded commented Jan 22, 2025

Bug summary

If you call .result() on a submitted async task mypy believes that the call should be awaited. However the .result() is not a coroutine and following the mypy suggestion results in a TypeError.

Example:

from prefect import task, flow
import asyncio


@task
async def test_task() -> int:
    return 1

def test_function(a:int) -> int:
    return a

@flow 
async def test_flow() -> None:
    a = test_task.submit().result()
    print(type(a))
    b = test_function(a)
    print(b)

if __name__ == "__main__" :
    asyncio.run(test_flow())

The code above runs correctly outputting

<class 'int'>
1

However mypy thinks that line 16 ,b = test_function(a), has a problem

test.py:16: error: Argument 1 to "test_function" has incompatible type "Coroutine[Any, Any, int]"; expected "int"  [arg-type]
test.py:16: note: Maybe you forgot to use "await"?

If you await .result() you get:

TypeError: object int can't be used in 'await' expression

Version info

mypy   1.14.1    
prefect  3.1.13 | 3.1.14.dev3

Additional context

No response

@mthanded mthanded added the bug Something isn't working label Jan 22, 2025
@mthanded mthanded changed the title Mypy incorrectly suggests that .result() for submitted async task should be awaited Incorrect type on .result() for a submitted async task results in invalid mypy suggestion Jan 22, 2025
@zzstoatzz
Copy link
Collaborator

zzstoatzz commented Jan 27, 2025

thanks for the issue @mthanded - I think this is fundamentally the same issue as #15008. I think it's worth tracking this independently though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants