From: Daniele Varrazzo Date: Sat, 28 Aug 2021 16:46:03 +0000 (+0200) Subject: Improve TypeRegistry docs X-Git-Tag: 3.0.beta1~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5b92c16e3b151dc57ecbbcabddfda27a1751e8c2;p=thirdparty%2Fpsycopg.git Improve TypeRegistry docs --- diff --git a/docs/api/abc.rst b/docs/api/abc.rst index 7d311f943..66ee12d12 100644 --- a/docs/api/abc.rst +++ b/docs/api/abc.rst @@ -46,9 +46,10 @@ checking. from the context, but this may fail in some contexts and may require a cast (e.g. specifying :samp:`%s::{type}` for its placeholder). - You can use the `psycopg.adapters`\ ``.``\ `~psycopg.adapt.AdaptersMap.types` - registry to find the OID of builtin types, and you can use - `~psycopg.types.TypeInfo` to extend the registry to custom types. + You can use the `psycopg.adapters`\ ``.``\ + `~psycopg.adapt.AdaptersMap.types` registry to find the OID of builtin + types, and you can use `~psycopg.types.TypeInfo` to extend the + registry to custom types. .. automethod:: get_key .. automethod:: upgrade diff --git a/docs/api/types.rst b/docs/api/types.rst index f9c653a4f..86b25ec80 100644 --- a/docs/api/types.rst +++ b/docs/api/types.rst @@ -105,6 +105,26 @@ its `~psycopg.adapt.AdaptersMap.types` attribute. The global registry, from which the others inherit from, is available as `psycopg.adapters`\ ``.types``. + .. automethod:: __getitem__ + + .. code:: python + + >>> import psycopg + + >>> psycopg.adapters.types["text"] + + + >>> psycopg.adapters.types[23] + + + .. automethod:: get + + .. automethod:: get_oid + + .. code:: python + + >>> psycopg.adapters.types.get_oid("text[]") + 1009 .. _numeric-wrappers: diff --git a/psycopg/psycopg/_typeinfo.py b/psycopg/psycopg/_typeinfo.py index 551d14f93..93380e59c 100644 --- a/psycopg/psycopg/_typeinfo.py +++ b/psycopg/psycopg/_typeinfo.py @@ -288,7 +288,7 @@ class TypesRegistry: """ Return info about a type, specified by name or oid - The type name or oid may refer to the array too. + :param key: the name or oid of the type to look for. Raise KeyError if not found. """ @@ -312,9 +312,9 @@ class TypesRegistry: """ Return info about a type, specified by name or oid - The type name or oid may refer to the array too. + :param key: the name or oid of the type to look for. - Return None if not found. + Unlike `__getitem__`, return None if not found. """ try: return self[key] @@ -325,7 +325,9 @@ class TypesRegistry: """ Return the oid of a PostgreSQL type by name. - Return the array oid if the type ends with "[]" + :param key: the name of the type to look for. + + Return the array oid if the type ends with "``[]``" Raise KeyError if the name is unknown. """