https://github.com/python/cpython/commit/28b8d5ffccd355dad7c8fd2fbf7b7552083c7e14
commit: 28b8d5ffccd355dad7c8fd2fbf7b7552083c7e14
branch: main
author: John Seong <[email protected]>
committer: hugovk <[email protected]>
date: 2026-04-18T21:50:17+03:00
summary:

gh-133403: Add type annotations to generate_levenshtein_examples.py (#143317)

Co-authored-by: Hugo van Kemenade <[email protected]>

files:
M .github/workflows/mypy.yml
M Tools/build/generate_levenshtein_examples.py
M Tools/build/mypy.ini

diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml
index e5a5b3939e58e3..7f6571ef954576 100644
--- a/.github/workflows/mypy.yml
+++ b/.github/workflows/mypy.yml
@@ -19,6 +19,7 @@ on:
       - "Tools/build/consts_getter.py"
       - "Tools/build/deepfreeze.py"
       - "Tools/build/generate-build-details.py"
+      - "Tools/build/generate_levenshtein_examples.py"
       - "Tools/build/generate_sbom.py"
       - "Tools/build/generate_stdlib_module_names.py"
       - "Tools/build/mypy.ini"
diff --git a/Tools/build/generate_levenshtein_examples.py 
b/Tools/build/generate_levenshtein_examples.py
index 30dcc7cf1a1479..2396c8040ca539 100644
--- a/Tools/build/generate_levenshtein_examples.py
+++ b/Tools/build/generate_levenshtein_examples.py
@@ -13,7 +13,7 @@
 _CASE_COST = 1
 
 
-def _substitution_cost(ch_a, ch_b):
+def _substitution_cost(ch_a: str, ch_b: str) -> int:
     if ch_a == ch_b:
         return 0
     if ch_a.lower() == ch_b.lower():
@@ -22,7 +22,7 @@ def _substitution_cost(ch_a, ch_b):
 
 
 @lru_cache(None)
-def levenshtein(a, b):
+def levenshtein(a: str, b: str) -> int:
     if not a or not b:
         return (len(a) + len(b)) * _MOVE_COST
     option1 = levenshtein(a[:-1], b[:-1]) + _substitution_cost(a[-1], b[-1])
@@ -31,7 +31,7 @@ def levenshtein(a, b):
     return min(option1, option2, option3)
 
 
-def main():
+def main() -> None:
     parser = argparse.ArgumentParser(description=__doc__)
     parser.add_argument('output_path', metavar='FILE', type=str)
     parser.add_argument('--overwrite', dest='overwrite', action='store_const',
@@ -48,7 +48,7 @@ def main():
         )
         return
 
-    examples = set()
+    examples: set[tuple[str, str, int]] = set()
     # Create a lot of non-empty examples, which should end up with a Gauss-like
     # distribution for even costs (moves) and odd costs (case substitutions).
     while len(examples) < 9990:
diff --git a/Tools/build/mypy.ini b/Tools/build/mypy.ini
index 7d341afd1cd48b..5465e2d4b6171f 100644
--- a/Tools/build/mypy.ini
+++ b/Tools/build/mypy.ini
@@ -9,6 +9,7 @@ files =
     Tools/build/consts_getter.py,
     Tools/build/deepfreeze.py,
     Tools/build/generate-build-details.py,
+    Tools/build/generate_levenshtein_examples.py,
     Tools/build/generate_sbom.py,
     Tools/build/generate_stdlib_module_names.py,
     Tools/build/verify_ensurepip_wheels.py,

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to