]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Improve TypeRegistry docs
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 28 Aug 2021 16:46:03 +0000 (18:46 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 28 Aug 2021 16:46:03 +0000 (18:46 +0200)
docs/api/abc.rst
docs/api/types.rst
psycopg/psycopg/_typeinfo.py

index 7d311f943e0c99c9753acdba4c4cf1beec0132cf..66ee12d129c1224ede9c787b5fe7b5c62bc7b279 100644 (file)
@@ -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
index f9c653a4f4aedd3b9cc0dbc329d6262a7e3caa1a..86b25ec80052ae4bc5f15007472599df221486fa 100644 (file)
@@ -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"]
+           <TypeInfo: text (oid: 25, array oid: 1009)>
+
+           >>> psycopg.adapters.types[23]
+           <TypeInfo: int4 (oid: 23, array oid: 1007)>
+
+   .. automethod:: get
+
+   .. automethod:: get_oid
+
+       .. code:: python
+
+           >>> psycopg.adapters.types.get_oid("text[]")
+           1009
 
 .. _numeric-wrappers:
 
index 551d14f93fe41f7fb97794d945ee534761155dcb..93380e59c211d5f056250d6d9ff5ae69480cc600 100644 (file)
@@ -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.
         """