From 53017a208370e9965e78ecafa7f8968a78816826 Mon Sep 17 00:00:00 2001 From: yukinarit Date: Sun, 10 Mar 2024 19:04:15 +0900 Subject: [PATCH] Fix mypy type errors in tests --- pyproject.toml | 6 ++---- tests/common.py | 23 ++++++++++++++++------- tests/test_de.py | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f0cdd972..33e5f55e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,6 +101,8 @@ include = [ "serde/toml.py", "serde/yaml.py", "serde/pickle.py", + "tests/common.py", + "tests/imported.py", "tests/test_custom.py", "tests/test_kwonly.py", "tests/test_flatten.py", @@ -111,8 +113,6 @@ include = [ exclude = [ "serde/numpy.py", "bench", - "tests/common.py", - "tests/imported.py", "tests/test_basics.py", "tests/test_compat.py", "tests/test_core.py", @@ -135,8 +135,6 @@ exclude = [ "examples/alias.py", "examples/field_order.py", "bench", - "tests/common.py", - "tests/imported.py", "tests/test_basics.py", "tests/test_compat.py", "tests/test_core.py", diff --git a/tests/common.py b/tests/common.py index 99daf12d..5defdb99 100644 --- a/tests/common.py +++ b/tests/common.py @@ -180,7 +180,7 @@ def yaml_not_supported(se: Any, de: Any, opt: Any) -> bool: [param([1, 2], list[int]), param({"a": 1}, dict[str, int]), param((1, 1), tuple[int, int])] ) -types_combinations: List = [ +types_combinations: List[Any] = [ list(more_itertools.flatten(c)) for c in itertools.combinations(types, 2) ] @@ -191,7 +191,7 @@ def yaml_not_supported(se: Any, de: Any, opt: Any) -> bool: ] -def make_id_from_dict(d: Dict[str, str]) -> str: +def make_id_from_dict(d: Dict[str, Union[bool, str]]) -> str: if not d: return "none" else: @@ -199,24 +199,33 @@ def make_id_from_dict(d: Dict[str, str]) -> str: return f"{key}-{d[key]}" -def opt_case_ids(): +def opt_case_ids() -> List[str]: + """ + Create parametrize test id + """ return list(map(make_id_from_dict, opt_case)) -def type_ids(): +def type_ids() -> List[str]: + """ + Create parametrize test id + """ from serde.compat import typename - def make_id(pair: Tuple): + def make_id(pair: Tuple[Any, ...]) -> str: t, T, _ = pair return f"{typename(T)}({t})" return list(map(make_id, types)) -def type_combinations_ids(): +def type_combinations_ids() -> List[str]: + """ + Create parametrize test id + """ from serde.compat import typename - def make_id(quad: Tuple): + def make_id(quad: Tuple[Any, ...]) -> str: t, T, u, U = quad return f"{typename(T)}({t})-{typename(U)}({u})" diff --git a/tests/test_de.py b/tests/test_de.py index cb9503e8..00927044 100644 --- a/tests/test_de.py +++ b/tests/test_de.py @@ -5,7 +5,7 @@ from serde.de import from_obj -def test_from_obj(): +def test_from_obj() -> None: # Primitive assert 10 == from_obj(int, 10, False, False)