From dc3c1f22ed4bac8fd1c0ec238c581bc4aabbfa7d Mon Sep 17 00:00:00 2001 From: Francisco Del Roio Date: Tue, 26 Mar 2024 20:22:16 -0300 Subject: [PATCH] Added overloads to `MetaData.reflect()` method. Fixes: #11200 --- lib/sqlalchemy/sql/schema.py | 30 +++++++++++++++++++ .../typing/plain_files/ext/asyncio/engines.py | 6 ++++ 2 files changed, 36 insertions(+) diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 8436aac434..99bc212000 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -5687,6 +5687,36 @@ class MetaData(HasSchemaAttr): sorted(self.tables.values(), key=lambda t: t.key) # type: ignore ) + @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, diff --git a/test/typing/plain_files/ext/asyncio/engines.py b/test/typing/plain_files/ext/asyncio/engines.py index df4b0a0f64..4e147d2369 100644 --- a/test/typing/plain_files/ext/asyncio/engines.py +++ b/test/typing/plain_files/ext/asyncio/engines.py @@ -1,6 +1,7 @@ from typing import Any from sqlalchemy import Connection +from sqlalchemy import MetaData from sqlalchemy import select from sqlalchemy import text from sqlalchemy.ext.asyncio import create_async_engine @@ -71,3 +72,8 @@ async def asyncio() -> None: ce.statement cc = select(1).compile(conn) cc.statement + + async with e.connect() as conn: + metadata = MetaData() + + await conn.run_sync(metadata.reflect) -- 2.47.2