From 0184fcd920a86f4cd45f8eeaa5dbbfd0dd7c52a2 Mon Sep 17 00:00:00 2001 From: Artturin Date: Thu, 19 Oct 2023 09:16:44 +0300 Subject: [PATCH] mypy check everything move the strict enablement to the pyproject.toml so disabling checks works correctly because `--strict` takes precedence over the file Checking everything was disabled in 60205b9a due to (seemingly) a bug --- default.nix | 2 +- pyproject.toml | 3 +++ tests/conftest.py | 3 +-- tests/test_pr.py | 14 +++++++++----- tests/test_wip.py | 6 ++++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/default.nix b/default.nix index ccf54187..4ec5fa84 100644 --- a/default.nix +++ b/default.nix @@ -40,7 +40,7 @@ python3.pkgs.buildPythonApplication { echo -e "\x1b[32m## run ruff\x1b[0m" ruff . echo -e "\x1b[32m## run mypy\x1b[0m" - mypy --strict nixpkgs_review + mypy nixpkgs_review echo -e "\x1b[32m## run nixpkgs-review --help\x1b[0m" diff --git a/pyproject.toml b/pyproject.toml index 28af4378..3c33f69c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,10 +60,13 @@ exclude = ''' [tool.mypy] python_version = "3.10" +strict = true warn_redundant_casts = true disallow_untyped_calls = true disallow_untyped_defs = true no_implicit_optional = true +# # Missing type parameters for generic type "CaptureFixture" [type-arg] +disallow_any_generics = false [[tool.mypy.overrides]] module = "setuptools.*" diff --git a/tests/conftest.py b/tests/conftest.py index 5e0fef45..8ccfee57 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -137,7 +137,6 @@ def nixpkgs() -> Iterator[Nixpkgs]: yield setup_git(nixpkgs_path) -# pytest.fixture is untyped -@pytest.fixture # type: ignore +@pytest.fixture def helpers() -> type[Helpers]: return Helpers diff --git a/tests/test_pr.py b/tests/test_pr.py index 692a6716..3a401659 100644 --- a/tests/test_pr.py +++ b/tests/test_pr.py @@ -2,7 +2,7 @@ import shutil import subprocess -from unittest.mock import MagicMock, mock_open, patch +from unittest.mock import MagicMock, Mock, mock_open, patch import pytest @@ -13,14 +13,14 @@ @patch("nixpkgs_review.utils.shutil.which", return_value=None) -def test_default_to_nix_if_nom_not_found(mock_shutil): +def test_default_to_nix_if_nom_not_found(mock_shutil: Mock) -> None: return_value = nix_nom_tool() assert return_value == "nix" mock_shutil.assert_called_once() @pytest.mark.skipif(not shutil.which("nom"), reason="`nom` not found in PATH") -def test_pr_local_eval(helpers: Helpers, capfd) -> None: +def test_pr_local_eval(helpers: Helpers, capfd: pytest.CaptureFixture) -> None: with helpers.nixpkgs() as nixpkgs: with open(nixpkgs.path.joinpath("pkg1.txt"), "w") as f: f.write("foo") @@ -47,7 +47,9 @@ def test_pr_local_eval(helpers: Helpers, capfd) -> None: @patch("nixpkgs_review.cli.nix_nom_tool", return_value="nix") -def test_pr_local_eval_missing_nom(mock_tool, helpers: Helpers, capfd) -> None: +def test_pr_local_eval_missing_nom( + mock_tool: Mock, helpers: Helpers, capfd: pytest.CaptureFixture +) -> None: with helpers.nixpkgs() as nixpkgs: with open(nixpkgs.path.joinpath("pkg1.txt"), "w") as f: f.write("foo") @@ -74,7 +76,9 @@ def test_pr_local_eval_missing_nom(mock_tool, helpers: Helpers, capfd) -> None: assert "$ nix build" in captured.out -def test_pr_local_eval_without_nom(helpers: Helpers, capfd) -> None: +def test_pr_local_eval_without_nom( + helpers: Helpers, capfd: pytest.CaptureFixture +) -> None: with helpers.nixpkgs() as nixpkgs: with open(nixpkgs.path.joinpath("pkg1.txt"), "w") as f: f.write("foo") diff --git a/tests/test_wip.py b/tests/test_wip.py index dae528cc..8160c0eb 100644 --- a/tests/test_wip.py +++ b/tests/test_wip.py @@ -10,7 +10,7 @@ @pytest.mark.skipif(not shutil.which("nom"), reason="`nom` not found in PATH") -def test_wip_command(helpers: Helpers, capfd) -> None: +def test_wip_command(helpers: Helpers, capfd: pytest.CaptureFixture) -> None: with helpers.nixpkgs() as nixpkgs: with open(nixpkgs.path.joinpath("pkg1.txt"), "w") as f: f.write("foo") @@ -24,7 +24,9 @@ def test_wip_command(helpers: Helpers, capfd) -> None: assert "$ nom build" in captured.out -def test_wip_command_without_nom(helpers: Helpers, capfd) -> None: +def test_wip_command_without_nom( + helpers: Helpers, capfd: pytest.CaptureFixture +) -> None: with helpers.nixpkgs() as nixpkgs: with open(nixpkgs.path.joinpath("pkg1.txt"), "w") as f: f.write("foo")