From: Daniele Varrazzo Date: Thu, 21 Jan 2021 03:04:09 +0000 (+0100) Subject: Added a few docstrings on types registry X-Git-Tag: 3.0.dev0~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4188277394f17d44dfe81c2cd3f0868f98e83b1c;p=thirdparty%2Fpsycopg.git Added a few docstrings on types registry --- 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