]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove pep484 type comments from the code
authorFederico Caselli <cfederico87@gmail.com>
Thu, 13 May 2021 19:20:51 +0000 (21:20 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Sun, 16 May 2021 09:11:10 +0000 (11:11 +0200)
Current effort is around the stub package, and having typing in
two places makes thing worse, since the types here are usually
outdated compared to the version in the stubs.

Once v2 gets under way we can start consolidating the types
here.

Fixes: #6461
Change-Id: I7132a444bd7138123074bf5bc664b4bb119a85ce

19 files changed:
doc/build/changelog/unreleased_14/6461.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/engine/interfaces.py
lib/sqlalchemy/engine/result.py
lib/sqlalchemy/engine/url.py
lib/sqlalchemy/ext/asyncio/base.py
lib/sqlalchemy/ext/asyncio/engine.py
lib/sqlalchemy/ext/asyncio/result.py
lib/sqlalchemy/ext/asyncio/session.py
lib/sqlalchemy/orm/decl_api.py
lib/sqlalchemy/orm/interfaces.py
lib/sqlalchemy/orm/relationships.py
lib/sqlalchemy/orm/strategy_options.py
lib/sqlalchemy/sql/base.py
lib/sqlalchemy/sql/coercions.py
lib/sqlalchemy/sql/elements.py
lib/sqlalchemy/sql/selectable.py
lib/sqlalchemy/testing/plugin/pytestplugin.py
lib/sqlalchemy/testing/provision.py

diff --git a/doc/build/changelog/unreleased_14/6461.rst b/doc/build/changelog/unreleased_14/6461.rst
new file mode 100644 (file)
index 0000000..89ec7eb
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, pep484
+    :tickets: 6461
+
+    Remove pep484 types from the code.
+    Current effort is around the stub package, and having typing in
+    two places makes thing worse, since the types in the SQLAlchemy
+    source were usually outdated compared to the version in the stubs.
index 88c03a0113ae37b96f73e5455b15a5cbace351e5..92023b3b2db2a217f3716c982186306437c26f23 100644 (file)
@@ -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):
index 0df7c954e05322502508eb1d2339d016b1d4d758..b7190662f8c55ee201201ac829b06f05f56ecaea 100644 (file)
 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
index a8039594191e394f280ca77809c3529be72715d2..fb4a7a4f3a2ea385d45bac9043cfe90bfb80587b 100644 (file)
@@ -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`.
 
index 7db524b9f4c20ea7da81a41fd6c08147da269592..7898f912156db06e53ef559171edc2aa0774c629 100644 (file)
@@ -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__()``
index d11b059fd852c3a04f07e2b27035889f9ba9a691..76a2fbbde99ca2486799a15fe284749b39a01e6a 100644 (file)
@@ -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):
index 17ddb614abd6de77526d8ee20c30cf1e8759ec98..9cd3cb2f8b61c125b947132ffd71749cf206a6f0 100644 (file)
@@ -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):
index 6899fe0a61ff653d7296f554fdc0ea3e280b11d5..4781b3ead7753686f8e2cad65f335ffeaf9d2f98 100644 (file)
@@ -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
index 1b61d6ee305294fb58bf58f619c23664849aa62f..8d19819b00e009e18435fa9c509c56a0ccb9edfa 100644 (file)
@@ -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(
index 4e2c3a88601690bee904b8e921950ea73e83019d..e829de5f63933392e37f2cd348afc0dc4bca0119 100644 (file)
@@ -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,
index 68e1aa5cb0311737120187ff6624c173f9b736d7..ed38becf7fea35697be77541b009f4d5b66f0cdb 100644 (file)
@@ -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.
 
index bf166e181e88c46ee582313694107468985d4d5c..5d87ef797fc87c4a4b474b2dfb51ec975a5c5d2c 100644 (file)
@@ -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.
 
index 60ae69176cfd0478e9c9f974bd61deafbe16736b..e371442fdde39adc592b6d498770e2b0baf91b7b 100644 (file)
@@ -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.
 
index 8ff907ef03cd41f6ae717c8b6453a8852d346563..b7df927f150352aa4c268cf6cabab766dda1c302 100644 (file)
@@ -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")
index 517bfd57dd3191303f8f67f985cb74ab244aa474..36ac507ad3fd40e2433ccb06dcc52cd2e53aa609 100644 (file)
@@ -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):
index 169a6d8461d05cb018424ced1e6b5f4f5fe0ac57..f212cb079c2752d76c7fc46abd3a08fef0042294 100644 (file)
@@ -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("_")
index 7007bb430e70c997d2e2b930973f9a8d6e5d7cdc..9ef9e11626321aca872ee18cb208a2a2e0d4ac56 100644 (file)
@@ -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):
index 388d71c73676337a12fef05f961625a994750403..4e82f10c1966aec5f31db8600d1adac5bf9f3213 100644 (file)
@@ -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"]
index a976abee02945306a7de980aeb5dc5b191efe8da..a911ba69ceea506fc2886834d0321046e5d6eba2 100644 (file)
@@ -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(