From: Mike Bayer Date: Sat, 23 Mar 2024 20:59:40 +0000 (-0400) Subject: typing fix X-Git-Tag: rel_2_0_29~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a3ba1163cdbe1e5fffd6b62b00d61925b8be200;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git typing fix the most recent greenlet/asyncio commit introduced a typing error that only comes up under python3.10 due to the non-presence of asyncio.Runner in that version. do an intricate dance here along with another python-version-specific thing observed around the greenlet import. Change-Id: I1b220ab8ea633cdf43ad7e8abe826f758858b62a --- diff --git a/lib/sqlalchemy/util/_concurrency_py3k.py b/lib/sqlalchemy/util/_concurrency_py3k.py index defef1f6bf..5717d97061 100644 --- a/lib/sqlalchemy/util/_concurrency_py3k.py +++ b/lib/sqlalchemy/util/_concurrency_py3k.py @@ -243,11 +243,11 @@ def get_event_loop() -> asyncio.AbstractEventLoop: return asyncio.get_event_loop_policy().get_event_loop() -if py311: +if not TYPE_CHECKING and py311: _Runner = asyncio.Runner else: - class _Runner: # type: ignore[no-redef] + class _Runner: """Runner implementation for test only""" _loop: Union[None, asyncio.AbstractEventLoop, Literal[False]] diff --git a/lib/sqlalchemy/util/concurrency.py b/lib/sqlalchemy/util/concurrency.py index 96ba416cab..de6195de8f 100644 --- a/lib/sqlalchemy/util/concurrency.py +++ b/lib/sqlalchemy/util/concurrency.py @@ -18,7 +18,7 @@ from typing import TypeVar have_greenlet = False greenlet_error = None try: - import greenlet # type: ignore # noqa: F401 + import greenlet # type: ignore[import-untyped,unused-ignore] # noqa: F401,E501 except ImportError as e: greenlet_error = str(e) pass