From c60b528b681e2da8007e39ae628b34b4f81d5365 Mon Sep 17 00:00:00 2001 From: "Armen Zambrano G." <44410+armenzg@users.noreply.github.com> Date: Fri, 22 May 2026 17:57:07 -0400 Subject: [PATCH] chore(typing): Rename mypy stronglist helpers to weaklist Align helper script and test names with weaklist terminology so tooling names match current typing policy. Treat stronglist->weaklist module renames as replacements in the weaklist-addition guard to keep the transition passing checks. Co-authored-by: Cursor --- .github/codeowners-coverage-baseline.txt | 2 +- .pre-commit-config.yaml | 4 ++-- pyproject.toml | 2 +- ...py_stronglist.py => test_mypy_weaklist.py} | 4 ++-- ...k_stronglist.py => test_check_weaklist.py} | 2 +- .../test_prevent_weaklist_additions.py | 19 +++++++++++++++ ...onger_modules.py => test_sort_weaklist.py} | 4 ++-- ...{check_stronglist.py => check_weaklist.py} | 0 .../prevent_weaklist_additions.py | 23 +++++++++++++++++++ ...t_stronger_modules.py => sort_weaklist.py} | 0 10 files changed, 51 insertions(+), 9 deletions(-) rename tests/sentry/{test_mypy_stronglist.py => test_mypy_weaklist.py} (78%) rename tests/tools/mypy_helpers/{test_check_stronglist.py => test_check_weaklist.py} (98%) rename tests/tools/mypy_helpers/{test_sort_stronger_modules.py => test_sort_weaklist.py} (90%) rename tools/mypy_helpers/{check_stronglist.py => check_weaklist.py} (100%) rename tools/mypy_helpers/{sort_stronger_modules.py => sort_weaklist.py} (100%) diff --git a/.github/codeowners-coverage-baseline.txt b/.github/codeowners-coverage-baseline.txt index 734fcb38d43fe8..1fc6f7baf8e7f9 100644 --- a/.github/codeowners-coverage-baseline.txt +++ b/.github/codeowners-coverage-baseline.txt @@ -2379,7 +2379,7 @@ tests/sentry/test_dependencies.py tests/sentry/test_devimports.py tests/sentry/test_http.py tests/sentry/test_killswitches.py -tests/sentry/test_mypy_stronglist.py +tests/sentry/test_mypy_weaklist.py tests/sentry/test_no_create_or_update_usage.py tests/sentry/test_sdk_updates.py tests/sentry/test_stacktraces.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d90db83d43273f..94e3df6c896391 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -61,12 +61,12 @@ repos: types: [python] - id: sort-mypy-weaklist name: sort mypy weaklist - entry: python3 -m tools.mypy_helpers.sort_stronger_modules + entry: python3 -m tools.mypy_helpers.sort_weaklist files: ^pyproject\.toml$ language: python - id: check-mypy-weaklist name: check mypy weaklist - entry: python3 -m tools.mypy_helpers.check_stronglist pyproject.toml + entry: python3 -m tools.mypy_helpers.check_weaklist pyproject.toml files: (^pyproject\.toml$|\.py$) pass_filenames: false language: python diff --git a/pyproject.toml b/pyproject.toml index 4330e14cf42188..789d2e89cc0a7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2376,7 +2376,7 @@ module = [ "tests.sentry.test_devimports", "tests.sentry.test_http", "tests.sentry.test_killswitches", - "tests.sentry.test_mypy_stronglist", + "tests.sentry.test_mypy_weaklist", "tests.sentry.test_no_create_or_update_usage", "tests.sentry.test_sdk_updates", "tests.sentry.test_stacktraces", diff --git a/tests/sentry/test_mypy_stronglist.py b/tests/sentry/test_mypy_weaklist.py similarity index 78% rename from tests/sentry/test_mypy_stronglist.py rename to tests/sentry/test_mypy_weaklist.py index 36294a52eadd5a..eb730fbd71d5b7 100644 --- a/tests/sentry/test_mypy_stronglist.py +++ b/tests/sentry/test_mypy_weaklist.py @@ -5,12 +5,12 @@ import sys -def test_stronglist() -> None: +def test_weaklist() -> None: pyproject_path = os.path.join(os.path.dirname(__file__), "../../pyproject.toml") pyproject_path = os.path.relpath(pyproject_path) proc = subprocess.run( - (sys.executable, "-uSm", "tools.mypy_helpers.check_stronglist", pyproject_path), + (sys.executable, "-uSm", "tools.mypy_helpers.check_weaklist", pyproject_path), check=False, text=True, stdout=subprocess.PIPE, diff --git a/tests/tools/mypy_helpers/test_check_stronglist.py b/tests/tools/mypy_helpers/test_check_weaklist.py similarity index 98% rename from tests/tools/mypy_helpers/test_check_stronglist.py rename to tests/tools/mypy_helpers/test_check_weaklist.py index 0d78f95a7a0162..c1a2572fb403f7 100644 --- a/tests/tools/mypy_helpers/test_check_stronglist.py +++ b/tests/tools/mypy_helpers/test_check_weaklist.py @@ -1,6 +1,6 @@ import re -from tools.mypy_helpers.check_stronglist import _glob_to_re, main +from tools.mypy_helpers.check_weaklist import _glob_to_re, main def test_glob_to_re_exact_matches() -> None: diff --git a/tests/tools/mypy_helpers/test_prevent_weaklist_additions.py b/tests/tools/mypy_helpers/test_prevent_weaklist_additions.py index eed0b9ed374305..ac96f4db694480 100644 --- a/tests/tools/mypy_helpers/test_prevent_weaklist_additions.py +++ b/tests/tools/mypy_helpers/test_prevent_weaklist_additions.py @@ -129,6 +129,25 @@ def test_addition_and_removal_same_diff_only_addition_fails(tmp_path, capsys) -> assert "'d.e.f'" not in out +def test_stronglist_to_weaklist_rename_passes(tmp_path) -> None: + initial = """\ +[[tool.mypy.overrides]] +module = ["tests.sentry.test_mypy_stronglist"] +disallow_untyped_defs = false +""" + updated = """\ +[[tool.mypy.overrides]] +module = ["tests.sentry.test_mypy_weaklist"] +disallow_untyped_defs = false +""" + _init_repo(tmp_path) + _commit_pyproject(tmp_path, initial) + tmp_path.joinpath("pyproject.toml").write_text(updated) + + with contextlib.chdir(tmp_path): + assert main(("pyproject.toml",)) == 0 + + def test_unrelated_overrides_ignored(tmp_path) -> None: initial = """\ [[tool.mypy.overrides]] diff --git a/tests/tools/mypy_helpers/test_sort_stronger_modules.py b/tests/tools/mypy_helpers/test_sort_weaklist.py similarity index 90% rename from tests/tools/mypy_helpers/test_sort_stronger_modules.py rename to tests/tools/mypy_helpers/test_sort_weaklist.py index 8974d36fa70eeb..eac5d649aa6a75 100644 --- a/tests/tools/mypy_helpers/test_sort_stronger_modules.py +++ b/tests/tools/mypy_helpers/test_sort_weaklist.py @@ -1,9 +1,9 @@ from pathlib import Path -from tools.mypy_helpers.sort_stronger_modules import main +from tools.mypy_helpers.sort_weaklist import main -def test_sort_stronger_modules(tmp_path: Path) -> None: +def test_sort_weaklist(tmp_path: Path) -> None: src = """\ # before diff --git a/tools/mypy_helpers/check_stronglist.py b/tools/mypy_helpers/check_weaklist.py similarity index 100% rename from tools/mypy_helpers/check_stronglist.py rename to tools/mypy_helpers/check_weaklist.py diff --git a/tools/mypy_helpers/prevent_weaklist_additions.py b/tools/mypy_helpers/prevent_weaklist_additions.py index 17f0dd9724b8d9..652ddd37545910 100644 --- a/tools/mypy_helpers/prevent_weaklist_additions.py +++ b/tools/mypy_helpers/prevent_weaklist_additions.py @@ -29,6 +29,23 @@ def _modules_for_override_key(data: dict[str, object], key: str, filename: str) ) +def _is_weaklist_rename( + *, + added_module: str, + head_modules: frozenset[str], + staged_modules: frozenset[str], +) -> bool: + if "weaklist" not in added_module: + return False + + legacy_module = added_module.replace("weaklist", "stronglist") + return ( + legacy_module != added_module + and legacy_module in head_modules + and legacy_module not in staged_modules + ) + + def main(argv: Sequence[str] | None = None) -> int: parser = argparse.ArgumentParser(description="Prevent new additions to mypy override lists.") parser.add_argument("filenames", nargs="*") @@ -53,6 +70,12 @@ def main(argv: Sequence[str] | None = None) -> int: head_modules = _modules_for_override_key(head_data, key, filename) staged_modules = _modules_for_override_key(staged_data, key, filename) for mod in sorted(staged_modules - head_modules): + if _is_weaklist_rename( + added_module=mod, + head_modules=head_modules, + staged_modules=staged_modules, + ): + continue print( f"{filename}: '{mod}' was added to the {list_name} — " f"do not add new modules; {advice}." diff --git a/tools/mypy_helpers/sort_stronger_modules.py b/tools/mypy_helpers/sort_weaklist.py similarity index 100% rename from tools/mypy_helpers/sort_stronger_modules.py rename to tools/mypy_helpers/sort_weaklist.py