diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-11-26 10:17:38 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-11-29 13:46:23 -0500 |
commit | db85d28a857945ce021e27a187a14999eeb5c89e (patch) | |
tree | 3e402d745aa1d01a51198154ddda25fe96296056 /lib/sqlalchemy/testing | |
parent | 5eb407f84bdabdbcd68975dbf76dc4c0809d7373 (diff) | |
download | sqlalchemy-db85d28a857945ce021e27a187a14999eeb5c89e.tar.gz |
provide connectionfairy on initialize
This is so that dialect methods that are called within init
can assume the same argument structure as when they are called
in other places; we can nail down the type of object as well.
This change seems to mostly impact the isolation level routines
in the dialects, as these are called during initialize()
as well as on established connections. these methods can now
assume a non-proxied DBAPI connection object in all cases,
as it is commonly required that attributes like ".autocommit"
are set on the object which don't work well in a proxied
situation.
Other changes:
* adds an interface for the "connectionfairy" concept
called PoolProxiedConnection.
* Removes ``Connectable`` superclass of Connection.
``Connectable`` was originally meant to provide for the
"method which accepts connection or engine" theme. As this
pattern is greatly reduced in 2.0 and Engine no longer extends
from it, the ``Connectable`` superclass doesnt serve any real
purpose.
Leading from that, to set this in I also applied pep 484 annotations
to the Dialect base, and then in the interests of seeing some
of the typing information show up in my IDE did a little bit for Engine,
Connection and others. I hope that it's feasible that we can
add annotations to specific classes and attributes ahead of when we
actually try to mass-populate the whole library. This was
the original spirit of pep-484 that we can apply annotations
gradually. I do of course want to try to do a mass-populate
although i think even in that case we will end up doing a lot
of manual work anyway (in particular for the changes here which
are distinct from what the stubs have).
Fixes: #7122
Change-Id: I5dd7fbff8a7ae520a81c165091af12a6a68826db
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r-- | lib/sqlalchemy/testing/engines.py | 33 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_dialect.py | 6 |
2 files changed, 35 insertions, 4 deletions
diff --git a/lib/sqlalchemy/testing/engines.py b/lib/sqlalchemy/testing/engines.py index e17c09be7..52c2d3cbf 100644 --- a/lib/sqlalchemy/testing/engines.py +++ b/lib/sqlalchemy/testing/engines.py @@ -7,6 +7,10 @@ import collections import re +import typing +from typing import Any +from typing import Dict +from typing import Optional import warnings import weakref @@ -15,6 +19,13 @@ from .util import decorator from .util import gc_collect from .. import event from .. import pool +from ..util.typing import Literal + + +if typing.TYPE_CHECKING: + from ..engine import Engine + from ..engine.url import URL + from ..ext.asyncio import AsyncEngine class ConnectionKiller: @@ -264,14 +275,32 @@ def reconnecting_engine(url=None, options=None): return engine +@typing.overload +def testing_engine( + url: Optional["URL"] = None, + options: Optional[Dict[str, Any]] = None, + asyncio: Literal[False] = False, + transfer_staticpool: bool = False, +) -> "Engine": + ... + + +@typing.overload +def testing_engine( + url: Optional["URL"] = None, + options: Optional[Dict[str, Any]] = None, + asyncio: Literal[True] = True, + transfer_staticpool: bool = False, +) -> "AsyncEngine": + ... + + def testing_engine( url=None, options=None, asyncio=False, transfer_staticpool=False, ): - """Produce an engine configured by --options with optional overrides.""" - if asyncio: from sqlalchemy.ext.asyncio import create_async_engine as create_engine else: diff --git a/lib/sqlalchemy/testing/suite/test_dialect.py b/lib/sqlalchemy/testing/suite/test_dialect.py index 28fd99876..daaea085d 100644 --- a/lib/sqlalchemy/testing/suite/test_dialect.py +++ b/lib/sqlalchemy/testing/suite/test_dialect.py @@ -115,7 +115,9 @@ class IsolationLevelTest(fixtures.TestBase): eq_(conn.get_isolation_level(), non_default) - conn.dialect.reset_isolation_level(conn.connection) + conn.dialect.reset_isolation_level( + conn.connection.dbapi_connection + ) eq_(conn.get_isolation_level(), existing) @@ -223,7 +225,7 @@ class AutocommitIsolationTest(fixtures.TablesTest): c2 = conn.execution_options(isolation_level="AUTOCOMMIT") self._test_conn_autocommits(c2, True) - c2.dialect.reset_isolation_level(c2.connection) + c2.dialect.reset_isolation_level(c2.connection.dbapi_connection) self._test_conn_autocommits(conn, False) |