From cc4c5e9e25b59414ee2caebcafa45f3811c670a9 Mon Sep 17 00:00:00 2001 From: Aleksander Binion Date: Mon, 7 Oct 2024 14:54:47 -0400 Subject: [PATCH] ignore python 3.7 error + docs --- minject/asyncio_extensions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/minject/asyncio_extensions.py b/minject/asyncio_extensions.py index 6b840dc..3abbd94 100644 --- a/minject/asyncio_extensions.py +++ b/minject/asyncio_extensions.py @@ -4,7 +4,9 @@ """ try: - from asyncio import to_thread + # Python 3.7 mypy raises attr-defined error for to_thread, so + # we must ignore it here. + from asyncio import to_thread # type: ignore[attr-defined] # This is copy pasted from here: https://github.com/python/cpython/blob/03775472cc69e150ced22dc30334a7a202fc0380/Lib/asyncio/threads.py#L1-L25 except ImportError: """High-level support for working with threads in asyncio""" @@ -20,8 +22,9 @@ # Minject Specific Edit: I removed the '/' from the function signature, # as this is not supported in python 3.7 (added in python 3.8). # The '/' forces that "func" be passed positionally (I.E. first argument - # to to_thread). Users of this extension must be careful to pass the - # function as the first argument. + # to to_thread). Users of this extension must be careful to pass the argument + # to "func" positionally, or there could be different behavior + # when using minject in python 3.7 and python 3.9+. # original asyncio source: "async def to_thread(func, /, *args, **kwargs):" async def to_thread(func, *args, **kwargs): """Asynchronously run function *func* in a separate thread.