From: Daniele Varrazzo Date: Wed, 8 Apr 2020 09:59:47 +0000 (+1200) Subject: register_array() renamed to array.register() X-Git-Tag: 3.0.dev0~590 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5fc7ce5c313d9d87e75e28035928179802ac695f;p=thirdparty%2Fpsycopg.git register_array() renamed to array.register() --- diff --git a/psycopg3/types/array.py b/psycopg3/types/array.py index 13318cd17..ad4697c3e 100644 --- a/psycopg3/types/array.py +++ b/psycopg3/types/array.py @@ -274,7 +274,7 @@ class ArrayCasterBinary(ArrayCasterBase): return agg(dims) -def register_array( +def register( array_oid: int, base_oid: int, context: AdaptContext = None, @@ -287,7 +287,7 @@ def register_array( (Format.TEXT, ArrayCasterText), (Format.BINARY, ArrayCasterBinary), ): - tcname = f"{name}_array_{format.name.lower()}" + tcname = f"{name.title()}Array{format.name.title()}Caster" t = type(tcname, (base,), {"base_oid": base_oid}) TypeCaster.register(array_oid, t, context=context, format=format) @@ -304,4 +304,4 @@ def register_all_arrays() -> None: (t.oid, Format.TEXT) in TypeCaster.globals or (t.oid, Format.BINARY) in TypeCaster.globals ): - register_array(t.array_oid, t.oid, name=t.name) + register(t.array_oid, t.oid, name=t.name) diff --git a/psycopg3/types/composite.py b/psycopg3/types/composite.py index f5d67db6f..d7e5161ab 100644 --- a/psycopg3/types/composite.py +++ b/psycopg3/types/composite.py @@ -8,9 +8,9 @@ from collections import namedtuple from typing import Any, Callable, Generator, List, Sequence, Tuple, Union from typing import Optional, TYPE_CHECKING +from . import array from ..adapt import Format, TypeCaster, Transformer, AdaptContext from .oids import builtins, TypeInfo -from .array import register_array if TYPE_CHECKING: from ..connection import Connection @@ -86,7 +86,7 @@ def register( ) if info.array_oid: - register_array( + array.register( info.array_oid, info.oid, context=context, name=info.name ) diff --git a/tests/types/test_array.py b/tests/types/test_array.py index 4feb496be..4067d2f53 100644 --- a/tests/types/test_array.py +++ b/tests/types/test_array.py @@ -1,8 +1,7 @@ import pytest import psycopg3 -from psycopg3.types import builtins +from psycopg3.types import builtins, array from psycopg3.adapt import Format, Transformer -from psycopg3.types.array import register_array tests_str = [ @@ -107,7 +106,7 @@ def test_array_register(conn): res = cur.fetchone()[0] assert res == "{postgres=arwdDxt/postgres}" - register_array( + array.register( builtins["aclitem"].array_oid, builtins["aclitem"].oid, context=conn ) cur.execute("select '{postgres=arwdDxt/postgres}'::aclitem[]")