From: Daniele Varrazzo Date: Thu, 6 Aug 2020 02:29:08 +0000 (+0100) Subject: Dropped Transformer.dump() X-Git-Tag: 3.0.dev0~458^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1320fb9927c80ae7980807c444f842c67e5379db;p=thirdparty%2Fpsycopg.git Dropped Transformer.dump() --- diff --git a/psycopg3/psycopg3/proto.py b/psycopg3/psycopg3/proto.py index 51df11fd0..a8499e4eb 100644 --- a/psycopg3/psycopg3/proto.py +++ b/psycopg3/psycopg3/proto.py @@ -84,9 +84,6 @@ class Transformer(Protocol): def types_sequence(self) -> List[int]: ... - def dump(self, obj: Any, format: Format = Format.TEXT) -> Optional[bytes]: - ... - def get_dumper(self, obj: Any, format: Format) -> "Dumper": ... diff --git a/psycopg3/psycopg3/transform.py b/psycopg3/psycopg3/transform.py index f106ef4cc..0095ab45c 100644 --- a/psycopg3/psycopg3/transform.py +++ b/psycopg3/psycopg3/transform.py @@ -164,13 +164,6 @@ class Transformer: def types_sequence(self) -> List[int]: return self._oids - # TODO: drop? - def dump(self, obj: Any, format: Format = Format.TEXT) -> Optional[bytes]: - if obj is None: - return None - - return self.get_dumper(obj, format).dump(obj) - def get_dumper(self, obj: Any, format: Format) -> "Dumper": key = (type(obj), format) try: diff --git a/psycopg3_c/psycopg3_c/_psycopg3.pyi b/psycopg3_c/psycopg3_c/_psycopg3.pyi index f0e54b114..985f00109 100644 --- a/psycopg3_c/psycopg3_c/_psycopg3.pyi +++ b/psycopg3_c/psycopg3_c/_psycopg3.pyi @@ -37,9 +37,6 @@ class Transformer: self, objs: Iterable[Any], formats: Iterable[pq.Format] ) -> List[Optional[bytes]]: ... def types_sequence(self) -> List[int]: ... - def dump( - self, obj: Any, format: pq.Format = pq.Format.TEXT - ) -> Optional[bytes]: ... def get_dumper(self, obj: Any, format: pq.Format) -> "Dumper": ... def lookup_dumper(self, src: type, format: pq.Format) -> DumperType: ... def load_row(self, row: int) -> Optional[Tuple[Any, ...]]: ... diff --git a/psycopg3_c/psycopg3_c/transform.pyx b/psycopg3_c/psycopg3_c/transform.pyx index 310b1cba6..c1436547f 100644 --- a/psycopg3_c/psycopg3_c/transform.pyx +++ b/psycopg3_c/psycopg3_c/transform.pyx @@ -239,12 +239,6 @@ cdef class Transformer: def types_sequence(self) -> List[int]: return self._oids - def dump(self, obj: Any, format: Format = 0) -> Optional[bytes]: - if obj is None: - return None - - return self.get_dumper(obj, format).dump(obj) - def get_dumper(self, obj: Any, format: Format) -> "Dumper": key = (type(obj), format) try: diff --git a/tests/types/test_array.py b/tests/types/test_array.py index 9816c2f81..892354958 100644 --- a/tests/types/test_array.py +++ b/tests/types/test_array.py @@ -88,7 +88,7 @@ def test_dump_list_int(conn, obj, want): def test_bad_binary_array(input): tx = Transformer() with pytest.raises(psycopg3.DataError): - tx.dump(input, Format.BINARY) + tx.get_dumper(input, Format.BINARY).dump(input) @pytest.mark.parametrize("fmt_out", [Format.TEXT, Format.BINARY]) @@ -115,10 +115,12 @@ def test_array_register(conn): @pytest.mark.xfail -def test_array_mixed_numbers(): +@pytest.mark.parametrize( + "array, type", [([1, 32767], "int2"), ([1, 32768], "int4")] +) +def test_array_mixed_numbers(array, type): # TODO: must use the type accommodating the largest/highest precision tx = Transformer() - ad = tx.dump([1, 32767], Format.BINARY) - assert ad[1] == builtins["int2"].array_oid - ad = tx.dump([1, 32768], Format.BINARY) - assert ad[1] == builtins["int4"].array_oid + dumper = tx.get_dumper(array, Format.BINARY) + dumper.dump(array) + assert dumper.oid == builtins[type].array_oid diff --git a/tests/types/test_numeric.py b/tests/types/test_numeric.py index 22c4fc812..39acc883d 100644 --- a/tests/types/test_numeric.py +++ b/tests/types/test_numeric.py @@ -36,7 +36,8 @@ def test_dump_int(conn, val, expr): def test_dump_int_binary(): # TODO: int binary adaptation (must choose the fitting int2,4,8) tx = Transformer() - tx.dump(1, Format.BINARY) + n = 1 + tx.get_dumper(n, Format.BINARY).dump(n) @pytest.mark.parametrize( @@ -132,7 +133,8 @@ def test_dump_float_approx(conn, val, expr): def test_dump_float_binary(): # TODO: float binary adaptation tx = Transformer() - tx.dump(1.0, Format.BINARY) + n = 1.0 + tx.get_dumper(n, Format.BINARY).dump(n) @pytest.mark.parametrize( @@ -235,7 +237,8 @@ def test_roundtrip_numeric(conn, val): def test_dump_numeric_binary(): # TODO: numeric binary adaptation tx = Transformer() - tx.dump(Decimal(1), Format.BINARY) + n = Decimal(1) + tx.get_dumper(n, Format.BINARY).dump(n) @pytest.mark.xfail