From 1faa32e7a9b1c19ba6e9d91bea31bfd75bd76cbc Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 21 Oct 2024 12:03:05 -0400 Subject: [PATCH] chore: improve mypy Signed-off-by: Henry Schreiner --- .pre-commit-config.yaml | 2 ++ docs/main.py | 2 +- pyproject.toml | 18 +++++------------- test/test_custom_repair_wheel.py | 8 ++++---- unit_test/wheel_print_test.py | 2 +- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a59a70380..c52ca2f6c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,6 +32,7 @@ repos: - nox - packaging - pygithub + - pytest - rich - tomli - tomli_w @@ -40,6 +41,7 @@ repos: - types-jinja2 - types-pyyaml - types-requests + - types-setuptools - uv - validate-pyproject - id: mypy diff --git a/docs/main.py b/docs/main.py index 106cbf241..66066fa2e 100644 --- a/docs/main.py +++ b/docs/main.py @@ -9,7 +9,7 @@ def define_env(env: Any) -> None: "Hook function for mkdocs-macros" - @env.macro + @env.macro # type: ignore[misc] def subprocess_run(*args: str) -> str: "Run a subprocess and return the stdout" env = os.environ.copy() diff --git a/pyproject.toml b/pyproject.toml index 47c8464e6..ddc1ca5db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,19 +113,13 @@ files = [ ] warn_unused_configs = true -warn_redundant_casts = true -no_implicit_reexport = true -strict_equality = true -warn_unused_ignores = true -check_untyped_defs = true - -disallow_subclassing_any = true -disallow_any_generics = true -warn_return_any = true -no_implicit_optional = true +strict = true +disallow_untyped_defs = false +disallow_untyped_calls = false +disallow_incomplete_defs = false enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] -warn_unreachable = true +warn_unreachable = false [[tool.mypy.overrides]] module = "cibuildwheel.*" @@ -136,10 +130,8 @@ disallow_untyped_decorators = true [[tool.mypy.overrides]] module = [ - "setuptools", "setuptools._distutils", # needed even if only directly import setuptools._distutils.util "setuptools._distutils.util", - "pytest", # ignored in pre-commit to speed up check "bashlex", "bashlex.*", "importlib_resources", diff --git a/test/test_custom_repair_wheel.py b/test/test_custom_repair_wheel.py index bf9825665..833639e3f 100644 --- a/test/test_custom_repair_wheel.py +++ b/test/test_custom_repair_wheel.py @@ -33,10 +33,9 @@ def test(tmp_path, capfd): basic_project.generate(project_dir) num_builds = len(utils.cibuildwheel_get_build_identifiers(project_dir)) - if num_builds > 1: - expectation = pytest.raises(subprocess.CalledProcessError) - else: - expectation = does_not_raise() + expectation = ( + pytest.raises(subprocess.CalledProcessError) if num_builds > 1 else does_not_raise() + ) with expectation as exc_info: result = utils.cibuildwheel_run( @@ -48,6 +47,7 @@ def test(tmp_path, capfd): captured = capfd.readouterr() if num_builds > 1: + assert exc_info is not None assert "Build failed because a wheel named" in captured.err assert exc_info.value.returncode == 6 else: diff --git a/unit_test/wheel_print_test.py b/unit_test/wheel_print_test.py index 9ddb54050..e97d316d4 100644 --- a/unit_test/wheel_print_test.py +++ b/unit_test/wheel_print_test.py @@ -27,7 +27,7 @@ def test_no_printout_on_error(tmp_path, capsys): tmp_path.joinpath("example.1").touch() raise RuntimeError() - captured = capsys.readouterr() # type: ignore[unreachable] + captured = capsys.readouterr() assert captured.err == "" assert "example.0" not in captured.out