]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Make test_copy*.py mypy-clean
authorDenis Laxalde <denis.laxalde@dalibo.com>
Fri, 5 Nov 2021 10:18:03 +0000 (11:18 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 10 Nov 2021 01:57:39 +0000 (02:57 +0100)
pyproject.toml
tests/test_copy.py
tests/test_copy_async.py

index 837794df5cbf41a889c045460caf27234c5959e7..afa3e87fbcedf60a0570ebd168aff5eb0a8695a8 100644 (file)
@@ -26,6 +26,7 @@ files = [
     "tests/scripts",
     "tests/test_adapt.py",
     "tests/test_conninfo.py",
+    "tests/test_copy*.py",
     "tests/test_dns*",
     "tests/test_errors.py",
     "tests/test_prepared*.py",
index 3050822066a5626c4c63d9f3ffcfe3f4f1e91b21..05448f4a24d08628d08808e582da0b99457177a7 100644 (file)
@@ -31,7 +31,7 @@ sample_text = b"""\
 40\t\\N\tworld
 """
 
-sample_binary = """
+sample_binary_str = """
 5047 434f 5059 0aff 0d0a 00
 00 0000 0000 0000 00
 00 0300 0000 0400 0000 0a00 0000 0400 0000 1400 0000 0568 656c 6c6f
@@ -42,7 +42,8 @@ ff ff
 """
 
 sample_binary_rows = [
-    bytes.fromhex("".join(row.split())) for row in sample_binary.split("\n\n")
+    bytes.fromhex("".join(row.split()))
+    for row in sample_binary_str.split("\n\n")
 ]
 
 sample_binary = b"".join(sample_binary_rows)
@@ -289,7 +290,9 @@ def test_subclass_adapter(conn, format):
     if format == Format.TEXT:
         from psycopg.types.string import StrDumper as BaseDumper
     else:
-        from psycopg.types.string import StrBinaryDumper as BaseDumper
+        from psycopg.types.string import (  # type: ignore[no-redef]
+            StrBinaryDumper as BaseDumper,
+        )
 
     class MyStrDumper(BaseDumper):
         def dump(self, obj):
@@ -352,7 +355,9 @@ def test_copy_in_records(conn, format):
     with cur.copy(f"copy copy_in from stdin (format {format.name})") as copy:
         for row in sample_records:
             if format == Format.BINARY:
-                row = tuple(Int4(i) if isinstance(i, int) else i for i in row)
+                row = tuple(
+                    Int4(i) if isinstance(i, int) else i for i in row
+                )  # type: ignore[assignment]
             copy.write_row(row)
 
     data = cur.execute("select * from copy_in order by 1").fetchall()
@@ -576,7 +581,7 @@ def test_copy_to_leaks(dsn, faker, fmt, set_types, method, retries):
                         list(copy)
                     elif method == "row":
                         while 1:
-                            tmp = copy.read_row()
+                            tmp = copy.read_row()  # type: ignore[assignment]
                             if tmp is None:
                                 break
                     elif method == "rows":
index 5242f043752392289fe58290e31a913031be2759..c136c0283bfc791b88e2afef3bdbd7ccad6b38c5 100644 (file)
@@ -270,7 +270,9 @@ async def test_subclass_adapter(aconn, format):
     if format == Format.TEXT:
         from psycopg.types.string import StrDumper as BaseDumper
     else:
-        from psycopg.types.string import StrBinaryDumper as BaseDumper
+        from psycopg.types.string import (  # type: ignore[no-redef]
+            StrBinaryDumper as BaseDumper,
+        )
 
     class MyStrDumper(BaseDumper):
         def dump(self, obj):
@@ -336,7 +338,9 @@ async def test_copy_in_records(aconn, format):
     ) as copy:
         for row in sample_records:
             if format == Format.BINARY:
-                row = tuple(Int4(i) if isinstance(i, int) else i for i in row)
+                row = tuple(
+                    Int4(i) if isinstance(i, int) else i for i in row
+                )  # type: ignore[assignment]
             await copy.write_row(row)
 
     await cur.execute("select * from copy_in order by 1")
@@ -569,7 +573,7 @@ async def test_copy_to_leaks(dsn, faker, fmt, set_types, method, retries):
                         await alist(copy)
                     elif method == "row":
                         while 1:
-                            tmp = await copy.read_row()
+                            tmp = await copy.read_row()  # type: ignore[assignment]
                             if tmp is None:
                                 break
                     elif method == "rows":