From dd4199ac50314ae4349c8af0f0be87291bebf287 Mon Sep 17 00:00:00 2001 From: Stephanos Kuma Date: Fri, 13 Dec 2024 11:37:55 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Make=20linting=20stricter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 89 ++++++------------- .../yamk/command/test_make/test_exceptions.py | 4 +- tests/yamk/lib/test_utils.py | 4 +- 3 files changed, 29 insertions(+), 68 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 179881a..48302fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ classifiers = [ requires-python = ">=3.9" dependencies = [ "dj_settings~=6.0", - "pyutilkit~=0.5", + "pyutilkit~=0.8.0", ] [project.urls] @@ -78,7 +78,11 @@ target-version = [ [tool.mypy] check_untyped_defs = true +disallow_any_decorated = false # (strict mode): Remove all Any types +disallow_any_explicit = false # (strict mode): Remove all Any types +disallow_any_expr = false # many builtins are Any disallow_any_generics = true +disallow_any_unimported = true disallow_incomplete_defs = true disallow_subclassing_any = true disallow_untyped_calls = true @@ -87,13 +91,18 @@ disallow_untyped_defs = true extra_checks = true ignore_missing_imports = true no_implicit_reexport = true +show_column_numbers = true show_error_codes = true strict_equality = true -warn_return_any = true warn_redundant_casts = true +warn_return_any = true +warn_unused_configs = true warn_unused_ignores = true warn_unreachable = true -warn_unused_configs = true + +[[tool.mypy.overrides]] +module = "tests.*" +disallow_any_decorated = false # mock.MagicMock is Any [tool.ruff] src = [ @@ -103,73 +112,25 @@ target-version = "py39" [tool.ruff.lint] select = [ - "A", - "ANN", - "ARG", - "ASYNC", - "B", - "BLE", - "C4", - "COM", - "DTZ", - "E", - "EM", - "ERA", - "EXE", - "F", - "FA", - "FBT", - "FIX", - "FLY", - "FURB", - "G", - "I", - "ICN", - "INP", - "ISC", - "LOG", - "N", - "PGH", - "PERF", - "PIE", - "PL", - "PT", - "PTH", - "PYI", - "Q", - "RET", - "RSE", - "RUF", - "S", - "SIM", - "SLF", - "SLOT", - "T10", - "TCH", - "TD", - "TID", - "TRY", - "UP", - "W", - "YTT", + "ALL", ] ignore = [ - "ANN401", - "COM812", - "E501", - "FIX002", - "PLR09", - "TD002", - "TD003", - "TRY003", + "ANN401", # (strict mode): Remove all Any types + "C901", # Adding a limit to complexity is too arbitrary + "COM812", # Avoid magic trailing commas + "D10", # Not everything needs a docstring + "D203", # Prefer `no-blank-line-before-class` (D211) + "D213", # Prefer `multi-line-summary-first-line` (D212) + "E501", # Avoid clashes with black + "PLR09", # Adding a limit to complexity is too arbitrary + "T201", # (pyutilkit 0.9): use SGROutput instead of print ] [tool.ruff.lint.per-file-ignores] "tests/**" = [ - "FBT001", - "PLR2004", - "PT011", - "S101", + "FBT001", # Test arguments are handled by pytest + "PLR2004", # Tests should contain magic number comparisons + "S101", # Pytest needs assert statements ] [tool.ruff.lint.flake8-tidy-imports] diff --git a/tests/yamk/command/test_make/test_exceptions.py b/tests/yamk/command/test_make/test_exceptions.py index 17761ff..e850171 100644 --- a/tests/yamk/command/test_make/test_exceptions.py +++ b/tests/yamk/command/test_make/test_exceptions.py @@ -9,7 +9,7 @@ def test_make_raises_on_missing_target() -> None: make_command = get_make_command(cookbook_name=COOKBOOK, target="missing_target") - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="No recipe to build missing_target"): make_command.make() @@ -17,7 +17,7 @@ def test_make_raises_on_missing_requirement() -> None: make_command = get_make_command( cookbook_name=COOKBOOK, target="missing_requirement" ) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="No recipe to build .*missing_target"): make_command.make() diff --git a/tests/yamk/lib/test_utils.py b/tests/yamk/lib/test_utils.py index d4c9316..a63092a 100644 --- a/tests/yamk/lib/test_utils.py +++ b/tests/yamk/lib/test_utils.py @@ -90,7 +90,7 @@ def test_topological_sort_detects_cycles() -> None: node.add_requirement(root) dag = DAG(root) dag.add_node(node) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="Cyclic dependencies detected"): dag.topological_sort() @@ -101,7 +101,7 @@ def test_c3_sort_detects_cycles() -> None: node.add_requirement(root) dag = DAG(root) dag.add_node(node) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="Cannot compute c3_sort"): dag.c3_sort()