From 337caa2c74f37b80be55a3134fbe7da2b2d7a26f Mon Sep 17 00:00:00 2001 From: "Armen Zambrano G." <44410+armenzg@users.noreply.github.com> Date: Fri, 22 May 2026 17:18:10 -0400 Subject: [PATCH] ref(mypy): Rename sort_stronger_modules to sort_weaklist The new name matches the pre-commit hook id (sort-mypy-weaklist) and the rest of the weaklist tooling (check_stronglist, prevent_weaklist_additions). A re-export shim is kept at the old module path so getsentry's .pre-commit-config.yaml keeps working until it is updated to call the new name. Once getsentry is updated, a follow-up will remove the shim. Co-authored-by: Cursor --- .pre-commit-config.yaml | 2 +- ...onger_modules.py => test_sort_weaklist.py} | 4 +-- tools/mypy_helpers/sort_stronger_modules.py | 31 +--------------- tools/mypy_helpers/sort_weaklist.py | 35 +++++++++++++++++++ 4 files changed, 39 insertions(+), 33 deletions(-) rename tests/tools/mypy_helpers/{test_sort_stronger_modules.py => test_sort_weaklist.py} (90%) create mode 100644 tools/mypy_helpers/sort_weaklist.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d90db83d43273f..23ca21bb152062 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -61,7 +61,7 @@ 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 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/sort_stronger_modules.py b/tools/mypy_helpers/sort_stronger_modules.py index b3e33f36df2a51..33d3042d6a32c2 100644 --- a/tools/mypy_helpers/sort_stronger_modules.py +++ b/tools/mypy_helpers/sort_stronger_modules.py @@ -1,35 +1,6 @@ from __future__ import annotations -import argparse -from collections.abc import Sequence - - -def main(argv: Sequence[str] | None = None) -> int: - parser = argparse.ArgumentParser() - parser.add_argument("filenames", nargs="*") - args = parser.parse_args(argv) - - ret = 0 - for filename in args.filenames: - with open(filename) as f: - contents = f.read() - - rest = contents - b1, m1, rest = rest.partition("# begin: not yet strongly typed\n") - b2, m2, rest = rest.partition("module = [\n") - b3, m3, rest = rest.partition("]\n") - b4, m4, rest = rest.partition("# end: not yet strongly typed\n") - - b3 = "".join(sorted(frozenset(b3.splitlines(True)))) - - new_contents = b1 + m1 + b2 + m2 + b3 + m3 + b4 + m4 + rest - if new_contents != contents: - with open(filename, "w") as f: - f.write(new_contents) - ret = 1 - - return ret - +from tools.mypy_helpers.sort_weaklist import main if __name__ == "__main__": raise SystemExit(main()) diff --git a/tools/mypy_helpers/sort_weaklist.py b/tools/mypy_helpers/sort_weaklist.py new file mode 100644 index 00000000000000..b3e33f36df2a51 --- /dev/null +++ b/tools/mypy_helpers/sort_weaklist.py @@ -0,0 +1,35 @@ +from __future__ import annotations + +import argparse +from collections.abc import Sequence + + +def main(argv: Sequence[str] | None = None) -> int: + parser = argparse.ArgumentParser() + parser.add_argument("filenames", nargs="*") + args = parser.parse_args(argv) + + ret = 0 + for filename in args.filenames: + with open(filename) as f: + contents = f.read() + + rest = contents + b1, m1, rest = rest.partition("# begin: not yet strongly typed\n") + b2, m2, rest = rest.partition("module = [\n") + b3, m3, rest = rest.partition("]\n") + b4, m4, rest = rest.partition("# end: not yet strongly typed\n") + + b3 = "".join(sorted(frozenset(b3.splitlines(True)))) + + new_contents = b1 + m1 + b2 + m2 + b3 + m3 + b4 + m4 + rest + if new_contents != contents: + with open(filename, "w") as f: + f.write(new_contents) + ret = 1 + + return ret + + +if __name__ == "__main__": + raise SystemExit(main())