From: Daniele Varrazzo Date: Fri, 12 Aug 2022 02:00:12 +0000 (+0200) Subject: refactor: drop repeated operation in sync/async TypeInfo.fetch() X-Git-Tag: 3.1~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a7d39bf740d0d97dbe230d07177463668327431a;p=thirdparty%2Fpsycopg.git refactor: drop repeated operation in sync/async TypeInfo.fetch() --- diff --git a/psycopg/psycopg/_typeinfo.py b/psycopg/psycopg/_typeinfo.py index de9a7b9e7..6a20f871a 100644 --- a/psycopg/psycopg/_typeinfo.py +++ b/psycopg/psycopg/_typeinfo.py @@ -75,16 +75,15 @@ class TypeInfo: name: Union[str, "Identifier"], ) -> Any: """Query a system catalog to read information about a type.""" - from .connection_async import AsyncConnection - - if isinstance(conn, AsyncConnection): - return cls._fetch_async(conn, name) - from .sql import Composable + from .connection_async import AsyncConnection if isinstance(name, Composable): name = name.as_string(conn) + if isinstance(conn, AsyncConnection): + return cls._fetch_async(conn, name) + # This might result in a nested transaction. What we want is to leave # the function with the connection in the state we found (either idle # or intrans) @@ -100,20 +99,13 @@ class TypeInfo: @classmethod async def _fetch_async( - cls: Type[T], - conn: "AsyncConnection[Any]", - name: Union[str, "Identifier"], + cls: Type[T], conn: "AsyncConnection[Any]", name: str ) -> Optional[T]: """ Query a system catalog to read information about a type. Similar to `fetch()` but can use an asynchronous connection. """ - from .sql import Composable - - if isinstance(name, Composable): - name = name.as_string(conn) - try: async with conn.transaction(): async with conn.cursor(binary=True, row_factory=dict_row) as cur: