From: Daniele Varrazzo Date: Mon, 8 Feb 2021 01:37:57 +0000 (+0100) Subject: Expose TypeInfo objects from the `psycopg3.types` package X-Git-Tag: 3.0.dev0~122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=296c41991de7d64d3c61039a01b179fc43649a3b;p=thirdparty%2Fpsycopg.git Expose TypeInfo objects from the `psycopg3.types` package --- diff --git a/psycopg3/psycopg3/typeinfo.py b/psycopg3/psycopg3/_typeinfo.py similarity index 92% rename from psycopg3/psycopg3/typeinfo.py rename to psycopg3/psycopg3/_typeinfo.py index 67f0bd7bb..ce22aaffc 100644 --- a/psycopg3/psycopg3/typeinfo.py +++ b/psycopg3/psycopg3/_typeinfo.py @@ -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, diff --git a/psycopg3/psycopg3/adapt.py b/psycopg3/psycopg3/adapt.py index 789593d3c..9d1f35101 100644 --- a/psycopg3/psycopg3/adapt.py +++ b/psycopg3/psycopg3/adapt.py @@ -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 diff --git a/psycopg3/psycopg3/oids.py b/psycopg3/psycopg3/oids.py index 48c2ee900..057765a98 100644 --- a/psycopg3/psycopg3/oids.py +++ b/psycopg3/psycopg3/oids.py @@ -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() diff --git a/psycopg3/psycopg3/types/__init__.py b/psycopg3/psycopg3/types/__init__.py index 2b7bda463..18d7e5247 100644 --- a/psycopg3/psycopg3/types/__init__.py +++ b/psycopg3/psycopg3/types/__init__.py @@ -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 ( diff --git a/psycopg3/psycopg3/types/array.py b/psycopg3/psycopg3/types/array.py index b282d8583..d8d2be916 100644 --- a/psycopg3/psycopg3/types/array.py +++ b/psycopg3/psycopg3/types/array.py @@ -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): diff --git a/psycopg3/psycopg3/types/composite.py b/psycopg3/psycopg3/types/composite.py index f91f29b1b..e2275ff9b 100644 --- a/psycopg3/psycopg3/types/composite.py +++ b/psycopg3/psycopg3/types/composite.py @@ -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): diff --git a/psycopg3/psycopg3/types/range.py b/psycopg3/psycopg3/types/range.py index 43b9ccbd6..fdf996d2f 100644 --- a/psycopg3/psycopg3/types/range.py +++ b/psycopg3/psycopg3/types/range.py @@ -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