Repository navigation
Modernise code in Tools/clinic/ #104683
Description
Feature or enhancement
Modernise some Python anachronisms in Tools/clinic/, to make the code more readable and maintainable. Some things that can be easily done:
-
Use
dictinstead ofOrderedDict(gh-104683: Argument clinic: usedictoverOrderedDict#104647) -
Simplify code like this by using the
str.removesuffixandstr.removeprefixmethods, both new in Python 3.9:
cpython/Tools/clinic/clinic.py
Lines 2572 to 2575 in 06eeee9
name = f.__name__ if not name.endswith('_converter'): return f name = name[:-len('_converter')] (gh-104683: Modernise
clinic.pyusingstr.removeprefixandstr.removesuffix#104685) -
Pyupgrade (run using the
--py310-plussetting) also finds various things that can be modernised (gh-104683: ModerniseTools/clinic/using pyupgrade #104684) -
Refactor CLanguage.output_templates (see Modernise code in
Tools/clinic/#104683 (comment)) -
Put templating in a separate .py file, kind of like Tools/clinic/cpp.py
Cc. @erlend-aasland
Linked PRs
- gh-104683: Argument clinic: use
dictoverOrderedDict#104647 - gh-104683: Modernise
Tools/clinic/using pyupgrade #104684 - gh-104683: Modernise
clinic.pyusingstr.removeprefixandstr.removesuffix#104685 - gh-104683: clinic.py: Modernise
parse_converter()using pattern-matching #104696 - gh-104683:
clinic.py: Improve coverage for theparse_convertermethod #104729 - [3.11] gh-104683:
clinic.py: Improve coverage for theparse_convertermethod (#104729) #104730 - gh-104683: Modernise Argument Clinic parameter state machine #106362
- gh-104683: Rename clinic.test => clinic.test.c #106443
- [3.12] gh-104683: Rename Lib/test/clinic.test as Lib/test/clinic.test.c (GH-106443) #106444
- [3.11] gh-104683: Rename Lib/test/clinic.test as Lib/test/clinic.test.c (GH-106443) #106445
- gh-104683: clinic.py: refactor four simple classes as dataclasses #106476
- gh-104683: clinic.py: refactor
ParameterandFunctionas dataclasses #106477 - gh-104683: clinic.py: Don't needlessly reimplement
contextlib.redirect_stdout#106478 - gh-104683: Argument clinic: Minor readability improvements for
Destination.__init__#106652 - gh-104683: Argument clinic: modernise
cpp.Monitor#106698 - gh-104683: Argument clinic: use an enum to describe the different kinds of functions #106721
- gh-104683: Argument Clinic: Modernise parse_special_symbol() #106837
- gh-104683: Argument Clinic: Make most arguments to
ClassandFunctionrequired #107289 - gh-104683: Argument clinic: cleanup
state_modulename_name()#107340 - gh-104683: Argument clinic: pass
clinicas a parameter where possible #107435 - gh-104683: Argument clinic: Make the
filenameparameter toClinicrequired #107439 - gh-104683: Argument clinic: remove the
LandMineclass #107541 - gh-104683: Argument clinic: cleanup
DLSParserstate_foomethods #107543 - gh-104683: Argument Clinic: Refactor and simplify 'add docstring' states #107550
- gh-104683: Rework Argument Clinic error handling #107551
- gh-104683: Make Argument Clinic template strings class level members #107556
- gh-104683: Argument Clinic: refactor format_docstring() #107623
- gh-104683: Argument clinic: remove some unnecessary uses of
self.next()in the DSLParser #107635 - gh-104683: Argument Clinic: Use CConverter.length_name where possible #107638
- gh-104683: Improve consistency and test coverage of argument-clinic
__repr__functions #107667 - gh-104683: Add --exclude option to Argument Clinic CLI #107770
- gh-104683: Remove unused variables from
Tools/clinicand tests forTools/clinic#107771 - gh-104683: Argument Clinic: Params now render their own docstrings #107790
- gh-104683: Argument clinic: make
format_docstring()a method onFunctionobjects #107840 - gh-104683: Argument Clinic: Extract parse_function_names() helper #107964
- gh-104683: Argument Clinic: Remove unreachable code from _module_and_class() #108092
- gh-104683: Argument Clinic: Refactor the module and class resolver #108552
Activity
gh-104683: Argument clinic: use `dict` over `OrderedDict` (#104647)
gh-104683: Modernise `clinic.py` using `str.removeprefix` and `str.re…
erlend-aasland commentedon May 20, 2023
gh-104683: Modernise Tools/clinic/ (#104684)
gh-104683: `clinic.py`: Improve coverage for the `parse_converter` me…
pythongh-104683: `clinic.py`: Improve coverage for the `parse_convert…
gh-104683: clinic.py: Modernise `parse_converter()` using pattern-mat…
[3.11] gh-104683: `clinic.py`: Improve coverage for the `parse_conver…
erlend-aasland commentedon Jul 3, 2023
The
parameter_statestate machine could be made slightly more readable by using enums, for example:cpython/Tools/clinic/clinic.py
Lines 4711 to 4726 in 35963da
gh-104683: Modernise Argument Clinic parameter state machine (#106362)
pythongh-104683: Rename clinic.test => clinic.test.c
gh-104683: Rename Lib/test/clinic.test as Lib/test/clinic.test.c (#10…
pythongh-104683: Rename Lib/test/clinic.test as Lib/test/clinic.test.c (
33 remaining items
gh-104683: Add --exclude option to Argument Clinic CLI (#107770)
gh-104683: Argument Clinic: refactor format_docstring() (#107623)
pythongh-104683: Argument Clinic: Params now render their own docstrings
gh-104683: Remove unused variables from `Tools/clinic` and tests for …
gh-104683: Argument Clinic: Params now render their own docstrings (#…
pythongh-104683: Argument Clinic: Extract parse_names() helper
gh-104683: Argument Clinic: Extract parse function name helper (#107964)
pythongh-104683: Argument Clinic: Remove unreachable code from _modul…
gh-104683: Argument Clinic: Remove unreachable code from _module_and_…
pythongh-104683: Argument Clinic: Refactor the module and class resolver
gh-104683: Argument Clinic: Refactor the module and class resolver (#…
erlend-aasland commentedon Aug 30, 2023
Argument Clinic is now slightly more readable, thanks to the applied refactors. I suggest we continue to improve and modernise Argument Clinic, but now through more targeted issues; this issue has served its purpose. Thanks to everyone involved.
python/cpython#104683: Add --exclude option to Argument Clinic CLI (p…
python/cpython#104683: Add --exclude option to Argument Clinic CLI (p…