From 4188277394f17d44dfe81c2cd3f0868f98e83b1c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 21 Jan 2021 04:04:09 +0100 Subject: [PATCH] Added a few docstrings on types registry --- psycopg3/psycopg3/oids.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/psycopg3/psycopg3/oids.py b/psycopg3/psycopg3/oids.py index 5a54eca83..a30b52f72 100644 --- a/psycopg3/psycopg3/oids.py +++ b/psycopg3/psycopg3/oids.py @@ -61,6 +61,13 @@ class TypesRegistry: yield t def __getitem__(self, key: Union[str, int]) -> TypeInfo: + """ + Return info about a type, specified by name or oid + + The type name or oid may refer to the array too. + + Raise KeyError if not found. + """ if isinstance(key, str): if key.endswith("[]"): key = key[:-2] @@ -73,12 +80,26 @@ class TypesRegistry: ) def get(self, key: Union[str, int]) -> Optional[TypeInfo]: + """ + Return info about a type, specified by name or oid + + The type name or oid may refer to the array too. + + Return None if not found. + """ try: return self[key] except KeyError: return None def get_oid(self, name: str) -> int: + """ + Return the oid of a PostgreSQL type by name. + + Return the array oid if the type ends with "[]" + + Raise KeyError if the name is unknown. + """ t = self[name] if name.endswith("[]"): return t.array_oid -- 2.47.3