From a7d39bf740d0d97dbe230d07177463668327431a Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 12 Aug 2022 04:00:12 +0200 Subject: [PATCH] refactor: drop repeated operation in sync/async TypeInfo.fetch() --- psycopg/psycopg/_typeinfo.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) 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: -- 2.47.2