diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2021-05-18 02:15:26 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-05-18 02:15:26 +0000 |
commit | 1fa9f43d55d33b930fa147390091ac163e97b0e2 (patch) | |
tree | bfc2147331948c3cd41d01d43060210e0723b98e /lib/sqlalchemy/ext/asyncio/engine.py | |
parent | 6b36b58e6916e7e6d3f2c585a6d448a591d597e1 (diff) | |
parent | 71cb17c81d358646f8dfeac14e9662ce42bb94df (diff) | |
download | sqlalchemy-1fa9f43d55d33b930fa147390091ac163e97b0e2.tar.gz |
Merge "Remove pep484 type comments from the code"
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio/engine.py')
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/engine.py | 72 |
1 files changed, 28 insertions, 44 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/engine.py b/lib/sqlalchemy/ext/asyncio/engine.py index 17ddb614a..9cd3cb2f8 100644 --- a/lib/sqlalchemy/ext/asyncio/engine.py +++ b/lib/sqlalchemy/ext/asyncio/engine.py @@ -4,12 +4,6 @@ # # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php - -from typing import Any -from typing import Callable -from typing import Mapping -from typing import Optional - from . import exc as async_exc from .base import ProxyComparable from .base import StartableContext @@ -17,11 +11,8 @@ from .result import AsyncResult from ... import exc from ... import util from ...engine import create_engine as _create_engine -from ...engine import Result -from ...engine import Transaction from ...future import Connection from ...future import Engine -from ...sql import Executable from ...util.concurrency import greenlet_spawn @@ -92,11 +83,7 @@ class AsyncConnection(ProxyComparable, StartableContext, AsyncConnectable): "sync_connection", ) - def __init__( - self, - async_engine: "AsyncEngine", - sync_connection: Optional[Connection] = None, - ): + def __init__(self, async_engine, sync_connection=None): self.engine = async_engine self.sync_engine = async_engine.sync_engine self.sync_connection = sync_connection @@ -162,12 +149,12 @@ class AsyncConnection(ProxyComparable, StartableContext, AsyncConnectable): self._raise_for_not_started() return self.sync_connection - def begin(self) -> "AsyncTransaction": + def begin(self): """Begin a transaction prior to autobegin occurring.""" self._sync_connection() return AsyncTransaction(self) - def begin_nested(self) -> "AsyncTransaction": + def begin_nested(self): """Begin a nested transaction and return a transaction handle.""" self._sync_connection() return AsyncTransaction(self, nested=True) @@ -316,10 +303,10 @@ class AsyncConnection(ProxyComparable, StartableContext, AsyncConnectable): async def exec_driver_sql( self, - statement: Executable, - parameters: Optional[Mapping] = None, - execution_options: Mapping = util.EMPTY_DICT, - ) -> Result: + statement, + parameters=None, + execution_options=util.EMPTY_DICT, + ): r"""Executes a driver-level SQL string and return buffered :class:`_engine.Result`. @@ -346,10 +333,10 @@ class AsyncConnection(ProxyComparable, StartableContext, AsyncConnectable): async def stream( self, - statement: Executable, - parameters: Optional[Mapping] = None, - execution_options: Mapping = util.EMPTY_DICT, - ) -> AsyncResult: + statement, + parameters=None, + execution_options=util.EMPTY_DICT, + ): """Execute a statement and return a streaming :class:`_asyncio.AsyncResult` object.""" @@ -371,10 +358,10 @@ class AsyncConnection(ProxyComparable, StartableContext, AsyncConnectable): async def execute( self, - statement: Executable, - parameters: Optional[Mapping] = None, - execution_options: Mapping = util.EMPTY_DICT, - ) -> Result: + statement, + parameters=None, + execution_options=util.EMPTY_DICT, + ): r"""Executes a SQL statement construct and return a buffered :class:`_engine.Result`. @@ -426,10 +413,10 @@ class AsyncConnection(ProxyComparable, StartableContext, AsyncConnectable): async def scalar( self, - statement: Executable, - parameters: Optional[Mapping] = None, - execution_options: Mapping = util.EMPTY_DICT, - ) -> Any: + statement, + parameters=None, + execution_options=util.EMPTY_DICT, + ): r"""Executes a SQL statement construct and returns a scalar object. This method is shorthand for invoking the @@ -443,7 +430,7 @@ class AsyncConnection(ProxyComparable, StartableContext, AsyncConnectable): result = await self.execute(statement, parameters, execution_options) return result.scalar() - async def run_sync(self, fn: Callable, *arg, **kw) -> Any: + async def run_sync(self, fn, *arg, **kw): """Invoke the given sync callable passing self as the first argument. This method maintains the asyncio event loop all the way through @@ -529,7 +516,7 @@ class AsyncEngine(ProxyComparable, AsyncConnectable): await self.transaction.__aexit__(type_, value, traceback) await self.conn.close() - def __init__(self, sync_engine: Engine): + def __init__(self, sync_engine): if not sync_engine.dialect.is_async: raise exc.InvalidRequestError( "The asyncio extension requires an async driver to be used. " @@ -555,7 +542,7 @@ class AsyncEngine(ProxyComparable, AsyncConnectable): conn = self.connect() return self._trans_ctx(conn) - def connect(self) -> AsyncConnection: + def connect(self): """Return an :class:`_asyncio.AsyncConnection` object. The :class:`_asyncio.AsyncConnection` will procure a database @@ -573,7 +560,7 @@ class AsyncEngine(ProxyComparable, AsyncConnectable): return self._connection_cls(self) - async def raw_connection(self) -> Any: + async def raw_connection(self): """Return a "raw" DBAPI connection from the connection pool. .. seealso:: @@ -617,17 +604,14 @@ class AsyncTransaction(ProxyComparable, StartableContext): __slots__ = ("connection", "sync_transaction", "nested") - def __init__(self, connection: AsyncConnection, nested: bool = False): + def __init__(self, connection, nested=False): self.connection = connection - self.sync_transaction: Optional[Transaction] = None + self.sync_transaction = None self.nested = nested @classmethod def _from_existing_transaction( - cls, - connection: AsyncConnection, - sync_transaction: Transaction, - nested: bool = False, + cls, connection, sync_transaction, nested=False ): obj = cls.__new__(cls) obj.connection = connection @@ -645,11 +629,11 @@ class AsyncTransaction(ProxyComparable, StartableContext): return self.sync_transaction @property - def is_valid(self) -> bool: + def is_valid(self): return self._sync_transaction().is_valid @property - def is_active(self) -> bool: + def is_active(self): return self._sync_transaction().is_active async def close(self): |