Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add type annotations to :file:`Tools/build/generate_levenshtein_examples.py`
and configure mypy to check it with strict type checking.
Comment thread
hugovk marked this conversation as resolved.
Outdated
8 changes: 4 additions & 4 deletions Tools/build/generate_levenshtein_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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])
Expand All @@ -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',
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Tools/build/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading