From 50117506378d719882cf7b743d876258933e1dea Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 18:00:32 -0700 Subject: [PATCH] improve type annotations in tests --- fatamorgana/test/build_testfiles.py | 3 ++- fatamorgana/test/test_files_cblocks.py | 2 +- fatamorgana/test/test_files_cells.py | 2 +- fatamorgana/test/test_files_circles.py | 2 +- fatamorgana/test/test_files_ctrapezoids.py | 2 +- fatamorgana/test/test_files_empty.py | 1 - fatamorgana/test/test_files_layernames.py | 6 +++--- fatamorgana/test/test_files_modals.py | 2 +- fatamorgana/test/test_files_paths.py | 4 ++-- fatamorgana/test/test_files_placements.py | 10 +++++----- fatamorgana/test/test_files_polygons.py | 6 +++--- fatamorgana/test/test_files_properties.py | 4 ++-- fatamorgana/test/test_files_rectangles.py | 8 ++++---- fatamorgana/test/test_files_texts.py | 2 +- fatamorgana/test/test_files_trapezoids.py | 2 +- 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/fatamorgana/test/build_testfiles.py b/fatamorgana/test/build_testfiles.py index 649de3e..0f85fce 100644 --- a/fatamorgana/test/build_testfiles.py +++ b/fatamorgana/test/build_testfiles.py @@ -2,7 +2,8 @@ Build files equivalent to the test cases used by KLayout. """ -from typing import Callable, IO +from typing import IO +from collections.abc import Callable from . import ( diff --git a/fatamorgana/test/test_files_cblocks.py b/fatamorgana/test/test_files_cblocks.py index f4d32b5..18c76fa 100644 --- a/fatamorgana/test/test_files_cblocks.py +++ b/fatamorgana/test/test_files_cblocks.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr" from typing import IO from io import BytesIO diff --git a/fatamorgana/test/test_files_cells.py b/fatamorgana/test/test_files_cells.py index 40a6009..ba286a7 100644 --- a/fatamorgana/test/test_files_cells.py +++ b/fatamorgana/test/test_files_cells.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr" from typing import IO from io import BytesIO diff --git a/fatamorgana/test/test_files_circles.py b/fatamorgana/test/test_files_circles.py index b5d2cba..39e54a0 100644 --- a/fatamorgana/test/test_files_circles.py +++ b/fatamorgana/test/test_files_circles.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr" from typing import IO from io import BytesIO diff --git a/fatamorgana/test/test_files_ctrapezoids.py b/fatamorgana/test/test_files_ctrapezoids.py index b6f8bc0..c831146 100644 --- a/fatamorgana/test/test_files_ctrapezoids.py +++ b/fatamorgana/test/test_files_ctrapezoids.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr" from typing import IO from io import BytesIO diff --git a/fatamorgana/test/test_files_empty.py b/fatamorgana/test/test_files_empty.py index 1f9e6f3..a0fdbee 100644 --- a/fatamorgana/test/test_files_empty.py +++ b/fatamorgana/test/test_files_empty.py @@ -1,4 +1,3 @@ -# type: ignore from typing import IO from io import BytesIO import struct diff --git a/fatamorgana/test/test_files_layernames.py b/fatamorgana/test/test_files_layernames.py index 304835f..72e9af6 100644 --- a/fatamorgana/test/test_files_layernames.py +++ b/fatamorgana/test/test_files_layernames.py @@ -1,5 +1,5 @@ -# type: ignore -from typing import Sequence, IO +from typing import IO +from collections.abc import Sequence from io import BytesIO @@ -27,7 +27,7 @@ def base_tests(layout: OasisLayout) -> None: assert not layout.cellnames assert len(layout.cells) == 1 - assert layout.cells[0].name.string == 'A' + assert layout.cells[0].name.string == 'A' # type: ignore assert not layout.cells[0].properties diff --git a/fatamorgana/test/test_files_modals.py b/fatamorgana/test/test_files_modals.py index 7b6662e..fddc576 100644 --- a/fatamorgana/test/test_files_modals.py +++ b/fatamorgana/test/test_files_modals.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr" from typing import IO from io import BytesIO diff --git a/fatamorgana/test/test_files_paths.py b/fatamorgana/test/test_files_paths.py index e54315d..1dc1def 100644 --- a/fatamorgana/test/test_files_paths.py +++ b/fatamorgana/test/test_files_paths.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr" from typing import IO from io import BytesIO @@ -182,7 +182,7 @@ def test_file_1() -> None: else: assert gg.half_width == 12, msg - assert len(gg.point_list) == 3, msg + assert len(gg.point_list) == 3, msg # type: ignore assert_equal(gg.point_list, [[150, 0], [0, 50], [-50, 0]], err_msg=msg) if ii >= 4: diff --git a/fatamorgana/test/test_files_placements.py b/fatamorgana/test/test_files_placements.py index 7c5c500..ce4c8aa 100644 --- a/fatamorgana/test/test_files_placements.py +++ b/fatamorgana/test/test_files_placements.py @@ -1,5 +1,5 @@ -# type: ignore -from typing import Tuple, IO, cast, List +# mypy: disable-error-code="union-attr" +from typing import IO, cast from io import BytesIO from numpy.testing import assert_equal @@ -22,7 +22,7 @@ def base_tests(layout: OasisLayout) -> None: assert not layout.layers -def write_rectangle(buf: IO[bytes], pos: Tuple[int, int] = (300, -400)) -> None: +def write_rectangle(buf: IO[bytes], pos: tuple[int, int] = (300, -400)) -> None: write_uint(buf, 20) # RECTANGLE record write_byte(buf, 0b0111_1011) # SWHX_YRDL write_uint(buf, 1) # layer @@ -174,7 +174,7 @@ def test_file_1() -> None: assert not layout.cells[1].properties assert not layout.cells[1].geometry - geometry = cast(List[Rectangle], layout.cells[0].geometry) + geometry = cast(list[Rectangle], layout.cells[0].geometry) assert len(geometry) == 1 assert geometry[0].layer == 1 assert geometry[0].datatype == 2 @@ -843,7 +843,7 @@ def test_file_8() -> None: assert not layout.cells[2].properties assert not layout.cells[2].placements - geometry = cast(List[Rectangle], layout.cells[2].geometry) + geometry = cast(list[Rectangle], layout.cells[2].geometry) assert len(geometry) == 1 assert geometry[0].layer == 1 assert geometry[0].datatype == 2 diff --git a/fatamorgana/test/test_files_polygons.py b/fatamorgana/test/test_files_polygons.py index a3d9bfa..7ac0102 100644 --- a/fatamorgana/test/test_files_polygons.py +++ b/fatamorgana/test/test_files_polygons.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr, arg-type" from typing import IO from io import BytesIO @@ -445,7 +445,7 @@ def test_file_3() -> None: for ii, gg in enumerate(geometry): msg = f'Fail on polygon {ii}' assert len(gg.properties) == 1, msg - assert gg.properties[0].name == 0, msg + assert gg.properties[0].name == 0, msg # type: ignore assert len(gg.properties[0].values) == 1, msg - assert gg.properties[0].values[0] * 5 == 1, msg + assert gg.properties[0].values[0] * 5 == 1, msg # type: ignore diff --git a/fatamorgana/test/test_files_properties.py b/fatamorgana/test/test_files_properties.py index 7dab690..98fdede 100644 --- a/fatamorgana/test/test_files_properties.py +++ b/fatamorgana/test/test_files_properties.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr, index, arg-type" from typing import IO from io import BytesIO @@ -28,7 +28,7 @@ def write_file_common(buf: IO[bytes], variant: int) -> IO[bytes]: """ include_repetitions = variant in (2, 5) - def var_byte(buf, byte): + def var_byte(buf: IO[bytes], byte: int) -> None: if include_repetitions: byte |= 0b0100 write_byte(buf, byte) diff --git a/fatamorgana/test/test_files_rectangles.py b/fatamorgana/test/test_files_rectangles.py index 82ec564..204b9b3 100644 --- a/fatamorgana/test/test_files_rectangles.py +++ b/fatamorgana/test/test_files_rectangles.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr" from typing import IO from io import BytesIO @@ -267,7 +267,7 @@ def test_file_2() -> None: prop = gg.properties[0] assert prop.name == 0, msg - assert len(prop.values) == 1, msg - assert prop.values[0].numerator == 1, msg - assert prop.values[0].denominator == 5, msg + assert len(prop.values) == 1, msg # type: ignore + assert prop.values[0].numerator == 1, msg # type: ignore + assert prop.values[0].denominator == 5, msg # type: ignore diff --git a/fatamorgana/test/test_files_texts.py b/fatamorgana/test/test_files_texts.py index 60679ce..0575618 100644 --- a/fatamorgana/test/test_files_texts.py +++ b/fatamorgana/test/test_files_texts.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr, index" from typing import IO from io import BytesIO diff --git a/fatamorgana/test/test_files_trapezoids.py b/fatamorgana/test/test_files_trapezoids.py index e57b8f7..262f449 100644 --- a/fatamorgana/test/test_files_trapezoids.py +++ b/fatamorgana/test/test_files_trapezoids.py @@ -1,4 +1,4 @@ -# type: ignore +# mypy: disable-error-code="union-attr" from typing import IO from io import BytesIO