From: Denis Laxalde Date: Fri, 5 Nov 2021 10:18:03 +0000 (+0100) Subject: Make test_copy*.py mypy-clean X-Git-Tag: 3.0.3~3^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=482b7334a4dccae94406f36fd8e4f89067210cd5;p=thirdparty%2Fpsycopg.git Make test_copy*.py mypy-clean --- diff --git a/pyproject.toml b/pyproject.toml index 837794df5..afa3e87fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/tests/test_copy.py b/tests/test_copy.py index 305082206..05448f4a2 100644 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -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": diff --git a/tests/test_copy_async.py b/tests/test_copy_async.py index 5242f0437..c136c0283 100644 --- a/tests/test_copy_async.py +++ b/tests/test_copy_async.py @@ -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":