mirror of
https://github.com/python/cpython.git
synced 2026-04-20 02:40:59 +00:00
gh-133403: Add type annotations to generate_levenshtein_examples.py (#143317)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
d81599eeb7
commit
28b8d5ffcc
3 changed files with 6 additions and 4 deletions
1
.github/workflows/mypy.yml
vendored
1
.github/workflows/mypy.yml
vendored
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue