https://github.com/python/cpython/commit/b0104a9cfe95ed2a18ab4854c25b86419091476a
commit: b0104a9cfe95ed2a18ab4854c25b86419091476a
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2026-04-19T12:22:26+03:00
summary:

[3.14] gh-133403: Add type annotations to generate_levenshtein_examples.py 
(GH-143317) (#148734)

Co-authored-by: John Seong <[email protected]>
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 ae2095690b2d8a..d7ccadf495c007 100644
--- a/.github/workflows/mypy.yml
+++ b/.github/workflows/mypy.yml
@@ -18,6 +18,7 @@ on:
       - "Tools/build/compute-changes.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 331bada6f47d2e..cff2ab21670704 100644
--- a/Tools/build/mypy.ini
+++ b/Tools/build/mypy.ini
@@ -8,6 +8,7 @@ files =
     Tools/build/compute-changes.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