Skip to content

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

Merged
hugovk merged 4 commits intopython:mainfrom
sandole:add-typing-generate-levenshtein
Apr 18, 2026
Merged

gh-133403: Add type annotations to generate_levenshtein_examples.py#143317
hugovk merged 4 commits intopython:mainfrom
sandole:add-typing-generate-levenshtein

Conversation

@sandole
Copy link
Copy Markdown
Contributor

@sandole sandole commented Dec 31, 2025

Summary

  • Added type annotations to Tools/build/generate_levenshtein_examples.py
  • Updated Tools/build/mypy.ini to include the file for strict type checking
  • Updated .github/workflows/mypy.yml to check the file in CI

Type annotations added

  • Function parameters and return types for _substitution_cost, levenshtein, and main
  • Variable type annotation for the examples set
  • Added from __future__ import annotations for cleaner syntax

Test plan

  • Ran mypy --config-file=Tools/build/mypy.ini Tools/build/generate_levenshtein_examples.py
  • All mypy strict checks pass with no issues

This continues the ongoing effort in #133403 to add type checking to more build tools.


📚 Documentation preview 📚: https://cpython-previews--143317.org.readthedocs.build/

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Dec 31, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Comment thread Doc/library/typing.rst Outdated
Comment thread Tools/build/generate_levenshtein_examples.py Outdated
Copy link
Copy Markdown
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we're OK with adding typing to arbitrary files. I'd prefer to get an approval from someone who works on this file.

@AlexWaygood AlexWaygood removed their request for review January 1, 2026 01:35
@sandole sandole force-pushed the add-typing-generate-levenshtein branch from ce4462f to 22a495d Compare January 1, 2026 02:51
@AA-Turner
Copy link
Copy Markdown
Member

I'd agree with Jelle, I also think we should weigh up churn cost for PRs in this category. This PR doesn't seem to be LLM generated at first glance, but I imagine this ('add type hints to X file') could be a magnet for such activity.

A

@AA-Turner AA-Turner added the pending The issue will be closed if no feedback is provided label Jan 1, 2026
@sandole
Copy link
Copy Markdown
Contributor Author

sandole commented Jan 1, 2026

sorry guys first time contributor here but would really like to be a regular contributor

who's the go-to guy for these CI / tooling changes?

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Jan 1, 2026

That would be any of the maintainer working on traceback.py. The original author's @ambv, but considering we actually didn't change this file since 2022, I think we won't ever have a change to change it in the future either.

Also, please avoid updating the branch if the CI is still green. It wastes CI resources as mentioned in https://devguide.python.org/getting-started/pull-request-lifecycle/#update-branch-button (more generally, please read the devguide).

Comment thread Misc/NEWS.d/next/Tools-Demos/2025-12-31-10-30-00.gh-issue-133403.aB3xYz.rst Outdated
@hugovk hugovk requested a review from webknjaz as a code owner March 21, 2026 17:35
@bedevere-app

This comment was marked as resolved.

@hugovk hugovk removed their request for review April 6, 2026 12:57
@vstinner
Copy link
Copy Markdown
Member

vstinner commented Apr 7, 2026

cc @sobolevn

Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you!

@sobolevn sobolevn removed the pending The issue will be closed if no feedback is provided label Apr 7, 2026
@sobolevn
Copy link
Copy Markdown
Member

sobolevn commented Apr 7, 2026

In my opinion, this is a really small PR that add pretty simple types. So, this is +1 from me :)

@hugovk hugovk merged commit 28b8d5f into python:main Apr 18, 2026
60 checks passed
@hugovk hugovk added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Apr 18, 2026
@miss-islington-app
Copy link
Copy Markdown

Thanks @sandole for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link
Copy Markdown

Thanks @sandole for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 18, 2026
…s.py (pythonGH-143317)

(cherry picked from commit 28b8d5f)

Co-authored-by: John Seong <39040639+sandole@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@miss-islington-app
Copy link
Copy Markdown

Sorry, @sandole and @hugovk, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 28b8d5ffccd355dad7c8fd2fbf7b7552083c7e14 3.13

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 18, 2026

GH-148734 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Apr 18, 2026
@hugovk hugovk removed the needs backport to 3.13 bugs and security fixes label Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants