Adding type hints to clinic.py will make it easier to debug, fix bugs, do code review, add new features, and triage. IMO, the churn is worth the effort in the long run.
Previous discussion
Since adding typing to the CPython code base has been a slightly controversial topic (obviously controversial for Lib/), I created a topic on Discourse and asked for feedback. So far, I have not received any discouragements :)
Since I've been ignorant to typing until now, I'd like to give this a shot myself; it'll be a nice opportunity to learn some new tricks.
EDIT:
Don't take this too serious; I don't want to block anybody from contributing. Please fire up PRs if you want (I appreciate if you tag me, though!)
Reacted by Jelle Zijlstra, sunmy2019, Jacob Nilsson and Ken Jin
A good place to start is by switching the instance fields in CConverter to use variable annotations. This is the cause of most of the existing mypy complaints.
As you add types, the type checker will become more useful. Once you've gotten a number of types in, I recommend upgrading to mypy --check-untyped-defs, and then possibly mypy --strict.
As recommended by @AlexWaygood, we should probably start by adding a minimal type check to the CI. (We really don't want to increase CI minutes too much.) In the beginning, perhaps an allow-list is the most manageable path forward. When that list starts to grow, we can consider switching to using a deny-list instead. Thoughts? PRs welcome :)
Here's a PR to add a mypy check in CI, checking only the Tools/clinic directory: #104421. The check completed in 20 seconds (and will only run on PRs that touch files in Tools/clinic/), so I doubt it will increase our use of CI minutes too much!
Activity
erlend-aasland commented on May 1, 2023
Since I've been ignorant to typing until now, I'd like to give this a shot myself; it'll be a nice opportunity to learn some new tricks.
EDIT:
Don't take this too serious; I don't want to block anybody from contributing. Please fire up PRs if you want (I appreciate if you tag me, though!)
sobolevn commented on May 3, 2023
@erlend-aasland feel free to ask for help/reviews :)
hauntsaninja commented on May 4, 2023
A good place to start is by switching the instance fields in CConverter to use variable annotations. This is the cause of most of the existing mypy complaints.
As you add types, the type checker will become more useful. Once you've gotten a number of types in, I recommend upgrading to mypy --check-untyped-defs, and then possibly mypy --strict.
I'm biased, but I think mypy docs are a generally useful reference: https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html
erlend-aasland commented on May 12, 2023
As recommended by @AlexWaygood, we should probably start by adding a minimal type check to the CI. (We really don't want to increase CI minutes too much.) In the beginning, perhaps an allow-list is the most manageable path forward. When that list starts to grow, we can consider switching to using a deny-list instead. Thoughts? PRs welcome :)
AlexWaygood commented on May 12, 2023
Here's a PR to add a mypy check in CI, checking only the Tools/clinic directory: #104421. The check completed in 20 seconds (and will only run on PRs that touch files in Tools/clinic/), so I doubt it will increase our use of CI minutes too much!
gh-104050: Run mypy on `clinic.py` in CI (#104421)
Merge branch 'main' into supermon
Merge branch 'main' into cached_property_docs
pythongh-104050: Add basic typing to CConverter in clinic.py
pythongh-104050: Don't star-import 'types' in Argument Clinic
pythongh-104050: Add more annotations to `Tools/clinic.py`
81 remaining items
pythongh-104050: Argument clinic: annotate `format_docstring()` (pyth…
pythongh-104050: Argument clinic: misc improvements to type annotatio…
pythongh-104050: Argument Clinic: Annotate `CRenderData.__init__` (py…
pythongh-104050: Argument clinic: improve typing around adding C conv…
pythongh-104050: Argument clinic: more misc typing coverage improveme…
pythongh-104050: Argument clinic: more misc typing improvements (pyth…
pythongh-104050: Argument clinic: annotate `post_parsing()` and `clea…
pythongh-104050: Argument clinic: improve typing around `parse_arg()`…
pythongh-104050: Argument clinic: Complete `get_destination_buffer` a…
pythongh-104050: Argument clinic: Annotate `str_converter_key()` (pyt…
gh-104050: Argument clinic: complete type annotations (#107399)
gh-104050: Argument clinic: enable mypy's `--warn-return-any` setting (…
AlexWaygood commented on Jul 29, 2023
44 merged PRs later, and clinic is now 100% fully typed! 🚀
erlend-aasland commented on Jul 29, 2023
A big thanks to everyone involved! 🎉❤️