]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Dropped Transformer.dump()
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 6 Aug 2020 02:29:08 +0000 (03:29 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 23 Aug 2020 18:24:02 +0000 (19:24 +0100)
psycopg3/psycopg3/proto.py
psycopg3/psycopg3/transform.py
psycopg3_c/psycopg3_c/_psycopg3.pyi
psycopg3_c/psycopg3_c/transform.pyx
tests/types/test_array.py
tests/types/test_numeric.py

index 51df11fd08e8d8fcfeb6a298722d1dba3fa5ede0..a8499e4eb4243d176ddd39fe8173fc1d42e6ef2e 100644 (file)
@@ -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":
         ...
 
index f106ef4cc698c1dc47c97da153b437cb88ec6cf8..0095ab45c0fdd6a13f3772c8d5c6eca4333ee80e 100644 (file)
@@ -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:
index f0e54b1149baa6e57611e90ec0c6696f7777f3f5..985f00109e4c2d30445800ef118572d1f4841283 100644 (file)
@@ -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, ...]]: ...
index 310b1cba6612576b3da4e4155ed68fc5eda7ddd7..c1436547f48aaf8fd14cc7ca0d771c6a67e0faa4 100644 (file)
@@ -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:
index 9816c2f81932036b846c1e659247d703c95bd9f5..892354958e4c1a599def37a8bae79b37a2913954 100644 (file)
@@ -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
index 22c4fc8126251233836f3ad42d759938312fe511..39acc883d50d905ba6214b222b5cc2389eb25a7b 100644 (file)
@@ -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