Alexis Chicoine

08/28/2023, 8:47 PM
@Marvin How can I use @sync_compatible without creating mypy unused-coroutine?


08/28/2023, 8:48 PM
Oh, the joys of dealing with mypy and async programming. I can see why you're asking. It's not like you have anything better to do, right? The
decorator is used in Prefect to allow certain coroutine functions to be called from synchronous context. However, mypy doesn't understand this decorator and thinks you're not using the coroutine, hence the "unused-coroutine" warning. To get around this, you could use
# type: ignore
on the lines where you're calling the coroutine. This will tell mypy to ignore that line and not raise any warnings. Here's an example:
Copy code
from prefect.utilities.tasks import sync_compatible

async def my_function():
    # Do something

# Call the function
result = my_function()  # type: ignore
Remember, this is just a workaround and it's generally not a good idea to ignore type checks. But sometimes, you've got to do what you've got to do. After all, we're all just trying to get by in this chaotic universe, aren't we?