From: Mike Bayer Date: Mon, 14 Mar 2022 18:34:05 +0000 (-0400) Subject: move compiler / pool critical casts away X-Git-Tag: rel_2_0_0b1~425 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35f82173e04b3209e07fcfc0606a7614108d018e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git move compiler / pool critical casts away callcount tests were being impacted by a few cast() calls, move them behind TYPE_CHECKING Change-Id: I633bbfe55313db94ebb22f87cc4216f8e50d807e --- diff --git a/lib/sqlalchemy/pool/base.py b/lib/sqlalchemy/pool/base.py index c9fb8cb341..5a9d28a289 100644 --- a/lib/sqlalchemy/pool/base.py +++ b/lib/sqlalchemy/pool/base.py @@ -637,7 +637,11 @@ class _ConnectionRecord(ConnectionPoolEntry): @classmethod def checkout(cls, pool: Pool) -> _ConnectionFairy: - rec = cast(_ConnectionRecord, pool._do_get()) + if TYPE_CHECKING: + rec = cast(_ConnectionRecord, pool._do_get()) + else: + rec = pool._do_get() + try: dbapi_connection = rec.get_connection() except Exception as err: diff --git a/lib/sqlalchemy/pool/impl.py b/lib/sqlalchemy/pool/impl.py index d1be3f5419..15ff8c75f5 100644 --- a/lib/sqlalchemy/pool/impl.py +++ b/lib/sqlalchemy/pool/impl.py @@ -20,6 +20,7 @@ from typing import List from typing import Optional from typing import Set from typing import Type +from typing import TYPE_CHECKING from typing import Union import weakref @@ -390,7 +391,10 @@ class SingletonThreadPool(Pool): def _do_get(self) -> ConnectionPoolEntry: try: - c = cast(ConnectionPoolEntry, self._conn.current()) + if TYPE_CHECKING: + c = cast(ConnectionPoolEntry, self._conn.current()) + else: + c = self._conn.current() if c: return c except AttributeError: diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index f28dceefce..db88496a09 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -48,6 +48,7 @@ from typing import Sequence from typing import Set from typing import Tuple from typing import Type +from typing import TYPE_CHECKING from typing import Union from . import base @@ -1767,7 +1768,9 @@ class SQLCompiler(Compiled): else: schema_prefix = "" - tablename = cast("NamedFromClause", table).name + if TYPE_CHECKING: + assert isinstance(table, NamedFromClause) + tablename = table.name if ( not effective_schema diff --git a/test/profiles.txt b/test/profiles.txt index 750b577800..ec1cba7241 100644 --- a/test/profiles.txt +++ b/test/profiles.txt @@ -203,8 +203,8 @@ test.aaa_profiling.test_orm.JoinedEagerLoadTest.test_build_query x86_64_linux_cp # TEST: test.aaa_profiling.test_orm.JoinedEagerLoadTest.test_fetch_results -test.aaa_profiling.test_orm.JoinedEagerLoadTest.test_fetch_results x86_64_linux_cpython_3.10_sqlite_pysqlite_dbapiunicode_cextensions 431905 -test.aaa_profiling.test_orm.JoinedEagerLoadTest.test_fetch_results x86_64_linux_cpython_3.10_sqlite_pysqlite_dbapiunicode_nocextensions 450605 +test.aaa_profiling.test_orm.JoinedEagerLoadTest.test_fetch_results x86_64_linux_cpython_3.10_sqlite_pysqlite_dbapiunicode_cextensions 440705 +test.aaa_profiling.test_orm.JoinedEagerLoadTest.test_fetch_results x86_64_linux_cpython_3.10_sqlite_pysqlite_dbapiunicode_nocextensions 458805 # TEST: test.aaa_profiling.test_orm.LoadManyToOneFromIdentityTest.test_many_to_one_load_identity