Fixed typing regression caused by PR :ticket:`11055` in version 2.0.29 that
attempted to add ``ParamSpec`` to the asyncio ``run_sync()`` methods, where
using :meth:`_asyncio.AsyncConnection.run_sync` with
meth:`_schema.MetaData.reflect` would fail on mypy due to a bug.
See https://github.com/python/mypy/issues/17093 for details.
Pull request courtesy of Francisco R. Del Roio
Fixes: #11200
Closes: #11201
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11201
Pull-request-sha:
49e10e0d2a7bbadf471212033e25b7616b99c092
Change-Id: Ie2ebaebd1bc1ee1b865b78561cb6cb8937e85eca
(cherry picked from commit
40fc02d93f3f8b4d9ae2f7bf987f5f965a761dd4)
--- /dev/null
+.. change::
+ :tags: bug, typing, regression
+ :tickets: 11200
+
+ Fixed typing regression caused by PR :ticket:`11055` in version 2.0.29 that
+ attempted to add ``ParamSpec`` to the asyncio ``run_sync()`` methods, where
+ using :meth:`_asyncio.AsyncConnection.run_sync` with
+ :meth:`_schema.MetaData.reflect` would fail on mypy due to a bug.
+ See https://github.com/python/mypy/issues/17093 for details.
+ Pull request courtesy of Francisco R. Del Roio
sorted(self.tables.values(), key=lambda t: t.key) # type: ignore
)
+ # overload needed to work around mypy this mypy
+ # https://github.com/python/mypy/issues/17093
+ @overload
+ def reflect(
+ self,
+ bind: Engine,
+ schema: Optional[str] = ...,
+ views: bool = ...,
+ only: Union[
+ _typing_Sequence[str], Callable[[str, MetaData], bool], None
+ ] = ...,
+ extend_existing: bool = ...,
+ autoload_replace: bool = ...,
+ resolve_fks: bool = ...,
+ **dialect_kwargs: Any,
+ ) -> None: ...
+
+ @overload
+ def reflect(
+ self,
+ bind: Connection,
+ schema: Optional[str] = ...,
+ views: bool = ...,
+ only: Union[
+ _typing_Sequence[str], Callable[[str, MetaData], bool], None
+ ] = ...,
+ extend_existing: bool = ...,
+ autoload_replace: bool = ...,
+ resolve_fks: bool = ...,
+ **dialect_kwargs: Any,
+ ) -> None: ...
+
@util.preload_module("sqlalchemy.engine.reflection")
def reflect(
self,
from typing import Any
from sqlalchemy import Connection
+from sqlalchemy import Enum
+from sqlalchemy import MetaData
from sqlalchemy import select
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine
ce.statement
cc = select(1).compile(conn)
cc.statement
+
+ async with e.connect() as conn:
+ metadata = MetaData()
+
+ await conn.run_sync(metadata.create_all)
+ await conn.run_sync(metadata.reflect)
+ await conn.run_sync(metadata.drop_all)
+
+ # Just to avoid creating new constructs manually:
+ for _, table in metadata.tables.items():
+ await conn.run_sync(table.create)
+ await conn.run_sync(table.drop)
+
+ # Indexes:
+ for index in table.indexes:
+ await conn.run_sync(index.create)
+ await conn.run_sync(index.drop)
+
+ # Test for enum types:
+ enum = Enum("a", "b")
+ await conn.run_sync(enum.create)
+ await conn.run_sync(enum.drop)