]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor: drop repeated operation in sync/async TypeInfo.fetch()
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 12 Aug 2022 02:00:12 +0000 (04:00 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 12 Aug 2022 02:00:12 +0000 (04:00 +0200)
psycopg/psycopg/_typeinfo.py

index de9a7b9e7400ae09bd25e91642ca34d2f5db7d1d..6a20f871a8d9a5c2ea6002cf4b85f80c03b712f3 100644 (file)
@@ -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: