diff options
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/interfaces.py | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/result.py | 1 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/url.py | 45 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/base.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/engine.py | 72 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/result.py | 42 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/session.py | 42 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/decl_api.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/interfaces.py | 18 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/relationships.py | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/strategy_options.py | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/base.py | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/coercions.py | 16 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 17 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/plugin/pytestplugin.py | 15 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/provision.py | 4 |
18 files changed, 72 insertions, 249 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 88c03a011..92023b3b2 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -991,13 +991,9 @@ from ...types import BLOB from ...types import BOOLEAN from ...types import DATE from ...types import VARBINARY -from ...util import compat from ...util import topological -if compat.TYPE_CHECKING: - from typing import Any - RESERVED_WORDS = set( [ "accessible", @@ -3284,7 +3280,6 @@ class MySQLDialect(default.DefaultDialect): return parser.parse(sql, charset) def _detect_charset(self, connection): - # type: (Any) -> str raise NotImplementedError() def _detect_casing(self, connection): diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index 0df7c954e..b7190662f 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -10,12 +10,6 @@ from .. import util from ..sql.compiler import Compiled # noqa from ..sql.compiler import TypeCompiler # noqa -from ..util import compat - -if compat.TYPE_CHECKING: - from typing import Any - - from .url import URL class Dialect(object): @@ -1241,7 +1235,6 @@ class CreateEnginePlugin(object): """ # noqa: E501 def __init__(self, url, kwargs): - # type: (URL, dict[str, Any]) -> None """Construct a new :class:`.CreateEnginePlugin`. The plugin object is instantiated individually for each call diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index a80395941..fb4a7a4f3 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -892,7 +892,6 @@ class Result(_WithKeys, ResultInternal): return self._metadata._row_as_tuple_getter(keys) def mappings(self): - # type() -> MappingResult """Apply a mappings filter to returned rows, returning an instance of :class:`_result.MappingResult`. diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index 7db524b9f..7898f9121 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -25,14 +25,6 @@ from ..util import collections_abc from ..util import compat -if compat.TYPE_CHECKING: - from typing import Mapping - from typing import Optional - from typing import Sequence - from typing import Tuple - from typing import Union - - class URL( util.namedtuple( "URL", @@ -102,15 +94,14 @@ class URL( @classmethod def create( cls, - drivername, # type: str - username=None, # type: Optional[str] - password=None, # type: Optional[Union[str, object]] - host=None, # type: Optional[str] - port=None, # type: Optional[int] - database=None, # type: Optional[str] - query=util.EMPTY_DICT, # type: Mapping[str, Union[str, Sequence[str]]] + drivername, + username=None, + password=None, + host=None, + port=None, + database=None, + query=util.EMPTY_DICT, ): - # type: (...) -> URL """Create a new :class:`_engine.URL` object. :param drivername: the name of the database backend. This name will @@ -214,15 +205,14 @@ class URL( def set( self, - drivername=None, # type: Optional[str] - username=None, # type: Optional[str] - password=None, # type: Optional[Union[str, object]] - host=None, # type: Optional[str] - port=None, # type: Optional[int] - database=None, # type: Optional[str] - query=None, # type: Optional[Mapping[str, Union[str, Sequence[str]]]] + drivername=None, + username=None, + password=None, + host=None, + port=None, + database=None, + query=None, ): - # type: (...) -> URL """return a new :class:`_engine.URL` object with modifications. Values are used if they are non-None. To set a value to ``None`` @@ -267,7 +257,6 @@ class URL( return self._replace(**kw) def _replace(self, **kw): - # type: (**object) -> URL """Override ``namedtuple._replace()`` to provide argument checking.""" if "drivername" in kw: @@ -283,7 +272,6 @@ class URL( return super(URL, self)._replace(**kw) def update_query_string(self, query_string, append=False): - # type: (str, bool) -> URL """Return a new :class:`_engine.URL` object with the :attr:`_engine.URL.query` parameter dictionary updated by the given query string. @@ -317,7 +305,6 @@ class URL( ) def update_query_pairs(self, key_value_pairs, append=False): - # type: (Sequence[Tuple[str, str]], bool) -> URL """Return a new :class:`_engine.URL` object with the :attr:`_engine.URL.query` parameter dictionary updated by the given sequence of key/value pairs @@ -382,7 +369,6 @@ class URL( return self.set(query=new_query) def update_query_dict(self, query_parameters, append=False): - # type: (Mapping[str, Union[str, Sequence[str]]], bool) -> URL """Return a new :class:`_engine.URL` object with the :attr:`_engine.URL.query` parameter dictionary updated by the given dictionary. @@ -428,7 +414,6 @@ class URL( return self.update_query_pairs(query_parameters.items(), append=append) def difference_update_query(self, names): - # type: (Sequence[str]) -> URL """ Remove the given names from the :attr:`_engine.URL.query` dictionary, returning the new :class:`_engine.URL`. @@ -513,7 +498,6 @@ class URL( ":meth:`_engine.URL.render_as_string` method.", ) def __to_string__(self, hide_password=True): - # type: (bool) -> str """Render this :class:`_engine.URL` object as a string. :param hide_password: Defaults to True. The password is not shown @@ -523,7 +507,6 @@ class URL( return self.render_as_string(hide_password=hide_password) def render_as_string(self, hide_password=True): - # type: (bool) -> str """Render this :class:`_engine.URL` object as a string. This method is used when the ``__str__()`` or ``__repr__()`` diff --git a/lib/sqlalchemy/ext/asyncio/base.py b/lib/sqlalchemy/ext/asyncio/base.py index d11b059fd..76a2fbbde 100644 --- a/lib/sqlalchemy/ext/asyncio/base.py +++ b/lib/sqlalchemy/ext/asyncio/base.py @@ -5,7 +5,7 @@ from . import exc as async_exc class StartableContext(abc.ABC): @abc.abstractmethod - async def start(self, is_ctxmanager=False) -> "StartableContext": + async def start(self, is_ctxmanager=False): pass def __await__(self): 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): diff --git a/lib/sqlalchemy/ext/asyncio/result.py b/lib/sqlalchemy/ext/asyncio/result.py index 6899fe0a6..4781b3ead 100644 --- a/lib/sqlalchemy/ext/asyncio/result.py +++ b/lib/sqlalchemy/ext/asyncio/result.py @@ -7,23 +7,12 @@ import operator -from ... import util from ...engine.result import _NO_ROW from ...engine.result import FilterResult from ...engine.result import FrozenResult from ...engine.result import MergedResult from ...util.concurrency import greenlet_spawn -if util.TYPE_CHECKING: - from typing import Any - from typing import Int - from typing import Iterator - from typing import List - from typing import Mapping - from typing import Optional - - from ...engine.result import Row - class AsyncCommon(FilterResult): async def close(self): @@ -77,7 +66,6 @@ class AsyncResult(AsyncCommon): return self def columns(self, *col_expressions): - # type: (*object) -> AsyncResult r"""Establish the columns that should be returned in each row. Refer to :meth:`_engine.Result.columns` in the synchronous @@ -88,7 +76,6 @@ class AsyncResult(AsyncCommon): return self._column_slices(col_expressions) async def partitions(self, size=None): - # type: (Optional[Int]) -> Iterator[List[Any]] """Iterate through sub-lists of rows of the size given. An async iterator is returned:: @@ -115,7 +102,6 @@ class AsyncResult(AsyncCommon): break async def fetchone(self): - # type: () -> Row """Fetch one row. When all rows are exhausted, returns None. @@ -138,7 +124,6 @@ class AsyncResult(AsyncCommon): return row async def fetchmany(self, size=None): - # type: (Optional[Int]) -> List[Row] """Fetch many rows. When all rows are exhausted, returns an empty list. @@ -160,7 +145,6 @@ class AsyncResult(AsyncCommon): return await greenlet_spawn(self._manyrow_getter, self, size) async def all(self): - # type: () -> List[Row] """Return all rows in a list. Closes the result set after invocation. Subsequent invocations @@ -183,7 +167,6 @@ class AsyncResult(AsyncCommon): return row async def first(self): - # type: () -> Row """Fetch the first row or None if no row is present. Closes the result set and discards remaining rows. @@ -207,7 +190,6 @@ class AsyncResult(AsyncCommon): return await greenlet_spawn(self._only_one_row, False, False, False) async def one_or_none(self): - # type: () -> Optional[Row] """Return at most one result or raise an exception. Returns ``None`` if the result has no rows. @@ -230,7 +212,6 @@ class AsyncResult(AsyncCommon): return await greenlet_spawn(self._only_one_row, True, False, False) async def scalar_one(self): - # type: () -> Any """Return exactly one scalar result or raise an exception. This is equivalent to calling :meth:`_asyncio.AsyncResult.scalars` and @@ -246,7 +227,6 @@ class AsyncResult(AsyncCommon): return await greenlet_spawn(self._only_one_row, True, True, True) async def scalar_one_or_none(self): - # type: () -> Optional[Any] """Return exactly one or no scalar result. This is equivalent to calling :meth:`_asyncio.AsyncResult.scalars` and @@ -262,7 +242,6 @@ class AsyncResult(AsyncCommon): return await greenlet_spawn(self._only_one_row, True, False, True) async def one(self): - # type: () -> Row """Return exactly one row or raise an exception. Raises :class:`.NoResultFound` if the result returns no @@ -294,7 +273,6 @@ class AsyncResult(AsyncCommon): return await greenlet_spawn(self._only_one_row, True, True, False) async def scalar(self): - # type: () -> Optional[Any] """Fetch the first column of the first row, and close the result set. Returns None if there are no rows to fetch. @@ -350,7 +328,6 @@ class AsyncResult(AsyncCommon): return MergedResult(self._metadata, (self,) + others) def scalars(self, index=0): - # type: (Int) -> AsyncScalarResult """Return an :class:`_asyncio.AsyncScalarResult` filtering object which will return single elements rather than :class:`_row.Row` objects. @@ -367,7 +344,6 @@ class AsyncResult(AsyncCommon): return AsyncScalarResult(self._real_result, index) def mappings(self): - # type() -> AsyncMappingResult """Apply a mappings filter to returned rows, returning an instance of :class:`_asyncio.AsyncMappingResult`. @@ -414,7 +390,6 @@ class AsyncScalarResult(AsyncCommon): self._unique_filter_state = real_result._unique_filter_state def unique(self, strategy=None): - # type: () -> AsyncScalarResult """Apply unique filtering to the objects returned by this :class:`_asyncio.AsyncScalarResult`. @@ -425,7 +400,6 @@ class AsyncScalarResult(AsyncCommon): return self async def partitions(self, size=None): - # type: (Optional[Int]) -> Iterator[List[Any]] """Iterate through sub-lists of elements of the size given. Equivalent to :meth:`_asyncio.AsyncResult.partitions` except that @@ -444,13 +418,11 @@ class AsyncScalarResult(AsyncCommon): break async def fetchall(self): - # type: () -> List[Any] """A synonym for the :meth:`_asyncio.AsyncScalarResult.all` method.""" return await greenlet_spawn(self._allrows) async def fetchmany(self, size=None): - # type: (Optional[Int]) -> List[Any] """Fetch many objects. Equivalent to :meth:`_asyncio.AsyncResult.fetchmany` except that @@ -461,7 +433,6 @@ class AsyncScalarResult(AsyncCommon): return await greenlet_spawn(self._manyrow_getter, self, size) async def all(self): - # type: () -> List[Any] """Return all scalar values in a list. Equivalent to :meth:`_asyncio.AsyncResult.all` except that @@ -482,7 +453,6 @@ class AsyncScalarResult(AsyncCommon): return row async def first(self): - # type: () -> Optional[Any] """Fetch the first object or None if no object is present. Equivalent to :meth:`_asyncio.AsyncResult.first` except that @@ -493,7 +463,6 @@ class AsyncScalarResult(AsyncCommon): return await greenlet_spawn(self._only_one_row, False, False, False) async def one_or_none(self): - # type: () -> Optional[Any] """Return at most one object or raise an exception. Equivalent to :meth:`_asyncio.AsyncResult.one_or_none` except that @@ -504,7 +473,6 @@ class AsyncScalarResult(AsyncCommon): return await greenlet_spawn(self._only_one_row, True, False, False) async def one(self): - # type: () -> Any """Return exactly one object or raise an exception. Equivalent to :meth:`_asyncio.AsyncResult.one` except that @@ -556,7 +524,6 @@ class AsyncMappingResult(AsyncCommon): return self._metadata.keys def unique(self, strategy=None): - # type: () -> AsyncMappingResult """Apply unique filtering to the objects returned by this :class:`_asyncio.AsyncMappingResult`. @@ -567,12 +534,10 @@ class AsyncMappingResult(AsyncCommon): return self def columns(self, *col_expressions): - # type: (*object) -> AsyncMappingResult r"""Establish the columns that should be returned in each row.""" return self._column_slices(col_expressions) async def partitions(self, size=None): - # type: (Optional[Int]) -> Iterator[List[Mapping]] """Iterate through sub-lists of elements of the size given. Equivalent to :meth:`_asyncio.AsyncResult.partitions` except that @@ -591,13 +556,11 @@ class AsyncMappingResult(AsyncCommon): break async def fetchall(self): - # type: () -> List[Mapping] """A synonym for the :meth:`_asyncio.AsyncMappingResult.all` method.""" return await greenlet_spawn(self._allrows) async def fetchone(self): - # type: () -> Mapping """Fetch one object. Equivalent to :meth:`_asyncio.AsyncResult.fetchone` except that @@ -613,7 +576,6 @@ class AsyncMappingResult(AsyncCommon): return row async def fetchmany(self, size=None): - # type: (Optional[Int]) -> List[Mapping] """Fetch many objects. Equivalent to :meth:`_asyncio.AsyncResult.fetchmany` except that @@ -625,7 +587,6 @@ class AsyncMappingResult(AsyncCommon): return await greenlet_spawn(self._manyrow_getter, self, size) async def all(self): - # type: () -> List[Mapping] """Return all scalar values in a list. Equivalent to :meth:`_asyncio.AsyncResult.all` except that @@ -647,7 +608,6 @@ class AsyncMappingResult(AsyncCommon): return row async def first(self): - # type: () -> Optional[Mapping] """Fetch the first object or None if no object is present. Equivalent to :meth:`_asyncio.AsyncResult.first` except that @@ -659,7 +619,6 @@ class AsyncMappingResult(AsyncCommon): return await greenlet_spawn(self._only_one_row, False, False, False) async def one_or_none(self): - # type: () -> Optional[Mapping] """Return at most one object or raise an exception. Equivalent to :meth:`_asyncio.AsyncResult.one_or_none` except that @@ -670,7 +629,6 @@ class AsyncMappingResult(AsyncCommon): return await greenlet_spawn(self._only_one_row, True, False, False) async def one(self): - # type: () -> Mapping """Return exactly one object or raise an exception. Equivalent to :meth:`_asyncio.AsyncResult.one` except that diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py index 1b61d6ee3..8d19819b0 100644 --- a/lib/sqlalchemy/ext/asyncio/session.py +++ b/lib/sqlalchemy/ext/asyncio/session.py @@ -4,27 +4,14 @@ # # 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 typing import TypeVar - from . import engine from . import result as _result from .base import StartableContext -from .engine import AsyncEngine from ... import util -from ...engine import Result from ...orm import Session -from ...sql import Executable from ...util.concurrency import greenlet_spawn -T = TypeVar("T") - - @util.create_proxy_methods( Session, ":class:`_orm.Session`", @@ -72,12 +59,7 @@ class AsyncSession: dispatch = None - def __init__( - self, - bind: AsyncEngine = None, - binds: Mapping[object, AsyncEngine] = None, - **kw - ): + def __init__(self, bind=None, binds=None, **kw): kw["future"] = True if bind: self.bind = bind @@ -114,7 +96,7 @@ class AsyncSession: with_for_update=with_for_update, ) - async def run_sync(self, fn: Callable[..., T], *arg, **kw) -> T: + async def run_sync(self, fn, *arg, **kw): """Invoke the given sync callable passing sync self as the first argument. @@ -143,12 +125,12 @@ class AsyncSession: async def execute( self, - statement: Executable, - params: Optional[Mapping] = None, - execution_options: Mapping = util.EMPTY_DICT, - bind_arguments: Optional[Mapping] = None, + statement, + params=None, + execution_options=util.EMPTY_DICT, + bind_arguments=None, **kw - ) -> Result: + ): """Execute a statement and return a buffered :class:`_engine.Result` object.""" @@ -165,12 +147,12 @@ class AsyncSession: async def scalar( self, - statement: Executable, - params: Optional[Mapping] = None, - execution_options: Mapping = util.EMPTY_DICT, - bind_arguments: Optional[Mapping] = None, + statement, + params=None, + execution_options=util.EMPTY_DICT, + bind_arguments=None, **kw - ) -> Any: + ): """Execute a statement and return a scalar result.""" result = await self.execute( diff --git a/lib/sqlalchemy/orm/decl_api.py b/lib/sqlalchemy/orm/decl_api.py index 4e2c3a886..e829de5f6 100644 --- a/lib/sqlalchemy/orm/decl_api.py +++ b/lib/sqlalchemy/orm/decl_api.py @@ -32,9 +32,6 @@ from ..sql.schema import MetaData from ..util import hybridmethod from ..util import hybridproperty -if util.TYPE_CHECKING: - from .mapper import Mapper - def has_inherited_table(cls): """Given a class, return True if any of the classes it inherits from has a @@ -885,7 +882,6 @@ class registry(object): return decorate def map_declaratively(self, cls): - # type: (type) -> Mapper """Map a class declaratively. In this form of mapping, the class is scanned for mapping information, diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index 68e1aa5cb..ed38becf7 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -41,13 +41,6 @@ from ..sql import visitors from ..sql.base import ExecutableOption from ..sql.traversals import HasCacheKey -if util.TYPE_CHECKING: - from typing import Any - from typing import List - from typing import Optional - - from .mapper import Mapper - from .util import AliasedInsp __all__ = ( "EXT_CONTINUE", @@ -398,9 +391,9 @@ class PropComparator(operators.ColumnOperators): def __init__( self, - prop, # type: MapperProperty - parentmapper, # type: Mapper - adapt_to_entity=None, # type: Optional[AliasedInsp] + prop, + parentmapper, + adapt_to_entity=None, ): self.prop = self.property = prop self._parententity = adapt_to_entity or parentmapper @@ -409,10 +402,7 @@ class PropComparator(operators.ColumnOperators): def __clause_element__(self): raise NotImplementedError("%r" % self) - def _bulk_update_tuples( - self, value # type: (operators.ColumnOperators) - ): - # type: (...) -> List[tuple[operators.ColumnOperators, Any]] + def _bulk_update_tuples(self, value): """Receive a SQL expression that represents a value in the SET clause of an UPDATE statement. diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index bf166e181..5d87ef797 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -50,12 +50,6 @@ from ..sql.util import selectables_overlap from ..sql.util import visit_binary_product -if util.TYPE_CHECKING: - from typing import Union - - from .util import AliasedInsp - - def remote(expr): """Annotate a portion of a primaryjoin expression with a 'remote' annotation. @@ -2086,7 +2080,7 @@ class RelationshipProperty(StrategizedProperty): @util.memoized_property @util.preload_module("sqlalchemy.orm.mapper") - def entity(self): # type: () -> Union[AliasedInsp, mapperlib.Mapper] + def entity(self): """Return the target mapped entity, which is an inspect() of the class or aliased class that is referred towards. diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index 60ae69176..e371442fd 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -32,12 +32,6 @@ from ..sql import visitors from ..sql.base import _generative from ..sql.base import Generative -if util.TYPE_CHECKING: - from typing import Sequence - - from .context import QueryContext - from ..sql.elements import ColumnElement - class Load(Generative, LoaderOption): """Represents loader options which modify the state of a @@ -119,7 +113,6 @@ class Load(Generative, LoaderOption): return load def _generate_extra_criteria(self, context): - # type: (QueryContext) -> Sequence[ColumnElement] """Apply the current bound parameters in a QueryContext to the "extra_criteria" stored with this Load object. diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index 8ff907ef0..b7df927f1 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -27,12 +27,10 @@ from .. import util from ..util import HasMemoized from ..util import hybridmethod -if util.TYPE_CHECKING: - from types import ModuleType -coercions = None # type: ModuleType -elements = None # type: ModuleType -type_api = None # type: ModuleType +coercions = None +elements = None +type_api = None PARSE_AUTOCOMMIT = util.symbol("PARSE_AUTOCOMMIT") NO_ARG = util.symbol("NO_ARG") diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py index 517bfd57d..36ac507ad 100644 --- a/lib/sqlalchemy/sql/coercions.py +++ b/lib/sqlalchemy/sql/coercions.py @@ -19,15 +19,13 @@ from .. import inspection from .. import util from ..util import collections_abc -if util.TYPE_CHECKING: - from types import ModuleType - -elements = None # type: ModuleType -lambdas = None # type: ModuleType -schema = None # type: ModuleType -selectable = None # type: ModuleType -sqltypes = None # type: ModuleType -traversals = None # type: ModuleType + +elements = None +lambdas = None +schema = None +selectable = None +sqltypes = None +traversals = None def _is_literal(element): diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 169a6d846..f212cb079 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -44,11 +44,6 @@ from .. import exc from .. import inspection from .. import util -if util.TYPE_CHECKING: - from typing import Any - from typing import Optional - from typing import Union - def collate(expression, collation): """Return the clause ``expression COLLATE collation``. @@ -422,7 +417,6 @@ class ClauseElement( ) def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement """Apply a 'grouping' to this :class:`_expression.ClauseElement`. This method is overridden by subclasses to return a "grouping" @@ -792,7 +786,6 @@ class ColumnElement( _alt_names = () def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement if ( against in (operators.and_, operators.or_, operators._asbool) and self.type._type_affinity is type_api.BOOLEANTYPE._type_affinity @@ -2074,7 +2067,6 @@ class TextClause( return self.type.comparator_factory(self) def self_group(self, against=None): - # type: (Optional[Any]) -> Union[Grouping, TextClause] if against is operators.in_op: return Grouping(self) else: @@ -2321,7 +2313,6 @@ class ClauseList( return list(itertools.chain(*[c._from_objects for c in self.clauses])) def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement if self.group and operators.is_precedent(self.operator, against): return Grouping(self) else: @@ -2572,7 +2563,6 @@ class BooleanClauseList(ClauseList, ColumnElement): return (self,) def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement if not self.clauses: return self else: @@ -3528,7 +3518,6 @@ class UnaryExpression(ColumnElement): return ClauseElement._negate(self) def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement if self.operator and operators.is_precedent(self.operator, against): return Grouping(self) else: @@ -3654,7 +3643,6 @@ class AsBoolean(WrapsColumnExpression, UnaryExpression): return self.element def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement return self def _negate(self): @@ -3736,7 +3724,6 @@ class BinaryExpression(ColumnElement): return self.left._from_objects + self.right._from_objects def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement if operators.is_precedent(self.operator, against): return Grouping(self) @@ -3795,7 +3782,6 @@ class Slice(ColumnElement): self.type = type_api.NULLTYPE def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement assert against is operator.getitem return self @@ -3813,7 +3799,6 @@ class GroupedElement(ClauseElement): __visit_name__ = "grouping" def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement return self def _ungroup(self): @@ -4389,7 +4374,6 @@ class Label(roles.LabeledColumnExprRole, ColumnElement): return self._element.self_group(against=operators.as_) def self_group(self, against=None): - # type: (Optional[Any]) -> ClauseElement return self._apply_to_inner(self._element.self_group, against=against) def _negate(self): @@ -5116,7 +5100,6 @@ class _anonymous_label(_truncated_label): def safe_construct( cls, seed, body, enclosing_label=None, sanitize_key=False ): - # type: (int, str, Optional[_anonymous_label]) -> _anonymous_label if sanitize_key: body = re.sub(r"[%\(\) \$]+", "_", body).strip("_") diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 7007bb430..9ef9e1162 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -58,10 +58,6 @@ from .. import exc from .. import util from ..inspection import inspect -if util.TYPE_CHECKING: - from typing import Any - from typing import Optional - class _OffsetLimitParam(BindParameter): inherit_cache = True @@ -2796,7 +2792,6 @@ class SelectBase( is_select = True def _generate_fromclause_column_proxies(self, fromclause): - # type: (FromClause) -> None raise NotImplementedError() def _refresh_for_new_column(self, column): @@ -3080,7 +3075,6 @@ class SelectStatementGrouping(GroupedElement, SelectBase): _is_select_container = True def __init__(self, element): - # type: (SelectBase) -> None self.element = coercions.expect(roles.SelectStatementRole, element) def _ensure_disambiguated_names(self): @@ -3107,7 +3101,6 @@ class SelectStatementGrouping(GroupedElement, SelectBase): return self.element def self_group(self, against=None): - # type: (Optional[Any]) -> FromClause return self def _generate_fromclause_column_proxies(self, subquery): @@ -3877,7 +3870,6 @@ class CompoundSelect(HasCompileState, GenerativeSelect): return self.selects[0]._scalar_type() def self_group(self, against=None): - # type: (Optional[Any]) -> FromClause return SelectStatementGrouping(self) def is_derived_from(self, fromclause): diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py index 388d71c73..4e82f10c1 100644 --- a/lib/sqlalchemy/testing/plugin/pytestplugin.py +++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py @@ -17,15 +17,6 @@ import sys import pytest - -try: - import typing -except ImportError: - pass -else: - if typing.TYPE_CHECKING: - from typing import Sequence - try: import xdist # noqa @@ -694,11 +685,9 @@ class PytestFixtureFunctions(plugin_base.FixtureFunctions): return fn else: if argnames is None: - _argnames = getargspec(fn).args[1:] # type: Sequence(str) + _argnames = getargspec(fn).args[1:] else: - _argnames = re.split( - r", *", argnames - ) # type: Sequence(str) + _argnames = re.split(r", *", argnames) if has_exclusions: _argnames += ["_exclusions"] diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py index a976abee0..a911ba69c 100644 --- a/lib/sqlalchemy/testing/provision.py +++ b/lib/sqlalchemy/testing/provision.py @@ -16,9 +16,6 @@ log = logging.getLogger(__name__) FOLLOWER_IDENT = None -if compat.TYPE_CHECKING: - from ..engine import URL - class register(object): def __init__(self): @@ -181,7 +178,6 @@ def _generate_driver_urls(url, extra_drivers): @register.init def generate_driver_url(url, driver, query_str): - # type: (URL, str, str) -> URL backend = url.get_backend_name() new_url = url.set( |