]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Expose TypeInfo objects from the `psycopg3.types` package
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 8 Feb 2021 01:37:57 +0000 (02:37 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 8 Feb 2021 01:37:57 +0000 (02:37 +0100)
psycopg3/psycopg3/_typeinfo.py [moved from psycopg3/psycopg3/typeinfo.py with 92% similarity]
psycopg3/psycopg3/adapt.py
psycopg3/psycopg3/oids.py
psycopg3/psycopg3/types/__init__.py
psycopg3/psycopg3/types/array.py
psycopg3/psycopg3/types/composite.py
psycopg3/psycopg3/types/range.py

similarity index 92%
rename from psycopg3/psycopg3/typeinfo.py
rename to psycopg3/psycopg3/_typeinfo.py
index 67f0bd7bbc25a85b566cffdc910e5c6fa6acb08a..ce22aaffc0165efb56b44a8ad4d17a1c51ffabef 100644 (file)
@@ -30,6 +30,8 @@ class TypeInfo:
     - configure a composite type adaptation using `register()`
     """
 
+    __module__ = "psycopg3.types"
+
     def __init__(
         self,
         name: str,
@@ -54,6 +56,15 @@ class TypeInfo:
     def fetch(
         cls: Type[T], conn: "Connection", name: Union[str, "Identifier"]
     ) -> Optional[T]:
+        """
+        Query a system catalog to read information about a type.
+
+        :param conn: the connection to query
+        :param name: the name of the type to query. It can include a schema
+            name.
+        :return: a `!TypeInfo` object populated with the type information,
+            `!None` if not found.
+        """
         from .sql import Composable
 
         if isinstance(name, Composable):
@@ -68,6 +79,11 @@ class TypeInfo:
     async def fetch_async(
         cls: Type[T], conn: "AsyncConnection", name: Union[str, "Identifier"]
     ) -> 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):
@@ -98,7 +114,9 @@ class TypeInfo:
         self,
         context: Optional["AdaptContext"] = None,
     ) -> None:
-
+        """
+        Register the type information, globally or in the specified *context*.
+        """
         if context:
             types = context.adapters.types
         else:
@@ -126,6 +144,8 @@ order by t.oid
 class RangeInfo(TypeInfo):
     """Manage information about a range type."""
 
+    __module__ = "psycopg3.types"
+
     def __init__(self, name: str, oid: int, array_oid: int, subtype_oid: int):
         super().__init__(name, oid, array_oid)
         self.subtype_oid = subtype_oid
@@ -152,6 +172,8 @@ where t.oid = %(name)s::regtype
 class CompositeInfo(TypeInfo):
     """Manage information about a composite type."""
 
+    __module__ = "psycopg3.types"
+
     def __init__(
         self,
         name: str,
index 789593d3cc9c58362124159a186ab03f546f7ae1..9d1f351012d88d75da4c0dfea323c2f9356a4599 100644 (file)
@@ -14,7 +14,7 @@ from . import errors as e
 from ._enums import Format as Format
 from .oids import postgres_types
 from .proto import AdaptContext, Buffer as Buffer
-from .typeinfo import TypesRegistry
+from ._typeinfo import TypesRegistry
 
 if TYPE_CHECKING:
     from .connection import BaseConnection
index 48c2ee9007e48a43cab7df8be939baa045263e6b..057765a988e7269efb16cc3dc7123a6f570fe302 100644 (file)
@@ -4,7 +4,7 @@ Maps of builtin types and names
 
 # Copyright (C) 2020-2021 The Psycopg Team
 
-from .typeinfo import TypeInfo, RangeInfo, TypesRegistry
+from ._typeinfo import TypeInfo, RangeInfo, TypesRegistry
 
 # Global objects with PostgreSQL builtins and globally registered user types.
 postgres_types = TypesRegistry()
index 2b7bda463947cd9f1b7c469ec1765860999c53ec..18d7e5247181a4802cbae760e4100e9b8993005b 100644 (file)
@@ -16,7 +16,7 @@ from .json import Json, Jsonb
 from .range import Range
 
 # Database types descriptors
-from ..typeinfo import TypeInfo, RangeInfo, CompositeInfo
+from .._typeinfo import TypeInfo, RangeInfo, CompositeInfo
 
 # Adapter objects
 from .text import (
index b282d8583ee06af5e065bb5dcf77e8399a54d76a..d8d2be9163935e2a1507029c884596e5923ed394 100644 (file)
@@ -14,7 +14,7 @@ from ..oids import postgres_types, TEXT_OID, TEXT_ARRAY_OID, INVALID_OID
 from ..adapt import Buffer, Dumper, Loader, Transformer
 from ..adapt import Format as Pg3Format
 from ..proto import AdaptContext
-from ..typeinfo import TypeInfo
+from .._typeinfo import TypeInfo
 
 
 class BaseListDumper(Dumper):
index f91f29b1b2b12e92e7d6cdbc8f74369009c13cd6..e2275ff9bffe55fce53849d95ced05f5dfd99771 100644 (file)
@@ -14,7 +14,7 @@ from .. import pq
 from ..oids import TEXT_OID
 from ..adapt import Buffer, Format, Dumper, Loader, Transformer
 from ..proto import AdaptContext
-from ..typeinfo import CompositeInfo
+from .._typeinfo import CompositeInfo
 
 
 class SequenceDumper(Dumper):
index 43b9ccbd664979116aacdb27c1d0c86be3819ec6..fdf996d2f2fbf7c5c4430910f5e86462ffe76f42 100644 (file)
@@ -13,7 +13,7 @@ from ..pq import Format
 from ..oids import postgres_types as builtins, INVALID_OID
 from ..adapt import Buffer, Dumper, Format as Pg3Format
 from ..proto import AdaptContext
-from ..typeinfo import RangeInfo
+from .._typeinfo import RangeInfo
 
 from .composite import SequenceDumper, BaseCompositeLoader