]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
move compiler / pool critical casts away
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Mar 2022 18:34:05 +0000 (14:34 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Mar 2022 18:34:05 +0000 (14:34 -0400)
callcount tests were being impacted by a few cast() calls,
move them behind TYPE_CHECKING

Change-Id: I633bbfe55313db94ebb22f87cc4216f8e50d807e

lib/sqlalchemy/pool/base.py
lib/sqlalchemy/pool/impl.py
lib/sqlalchemy/sql/compiler.py
test/profiles.txt

index c9fb8cb341d5185adac48385b9362bd71d29a7d9..5a9d28a2899961f10e0aca4275f1436cb2d7f0df 100644 (file)
@@ -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:
index d1be3f54195ddf4169017065c3bb17439852c3a0..15ff8c75f5fa68950df2dfe90a60ae3610829471 100644 (file)
@@ -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:
index f28dceefcee16137a4b724e2aef44bddb88e305f..db88496a09c6b53e34419d13eca0ce2ebbf72958 100644 (file)
@@ -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
index 750b577800b73d781e138044efd0a8293b70b1a9..ec1cba724120c6d7214828af6cfd283dd25dac7d 100644 (file)
@@ -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