-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernise code in Tools/clinic/
#104683
Comments
For code readability. Instances of `builtins.dict` have been ordered since 3.6, and have been guaranteed by the language to be ordered since Python 3.7. Argument Clinic now requires Python 3.10+.
…movesuffix` (#104685) Both methods were new in Python 3.9.
|
- Make some string interpolations more readable using f-strings or explicit parametrisation - Remove unneeded open() mode specifiers Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
The cpython/Tools/clinic/clinic.py Lines 4711 to 4726 in 35963da
|
Use enums and pattern matching to make the code more readable. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
pythonGH-106443) (cherry picked from commit a941bd6) Co-authored-by: Erlend E. Aasland <erlend@python.org>
pythonGH-106443) (cherry picked from commit a941bd6) Co-authored-by: Erlend E. Aasland <erlend@python.org>
* main: (39 commits) pythongh-102542 Remove unused bytes object and bytes slicing (python#106433) Clarify state of CancelledError in doc (python#106453) pythongh-64595: Fix regression in file write logic in Argument Clinic (python#106449) pythongh-104683: Rename Lib/test/clinic.test as Lib/test/clinic.test.c (python#106443) tp_flags docs: fix indentation (python#106420) pythongh-104050: Partially annotate Argument Clinic CLanguage class (python#106437) pythongh-106368: Add tests for formatting helpers in Argument Clinic (python#106415) pythongh-104050: Annotate Argument Clinic parameter permutation helpers (python#106431) pythongh-104050: Annotate toplevel functions in clinic.py (python#106435) pythongh-106320: Fix specialize.c compilation by including pycore_pylifecycle.h (python#106434) Add some codeowners for `Tools/clinic/` (python#106430) pythongh-106217: Truncate the issue body size of `new-bugs-announce-notifier` (python#106423) pythongh-61215: Rename `wait_until_any_call` to `wait_until_any_call_with` (python#106414) pythongh-106162: array: suppress warning in test_array (python#106404) pythongh-106320: Remove _PyInterpreterState_HasFeature() (python#106425) pythonGH-106360: Support very basic superblock introspection (python#106422) pythongh-106406: Fix _Py_IsInterpreterFinalizing() in _winapi.c (python#106408) pythongh-106396: Special-case empty format spec to gen empty JoinedStr node (python#106401) pythongh-106368: Add tests for permutation helpers in Argument Clinic (python#106407) pythonGH-106008: Fix refleak when peepholing `None` comparisons (python#106367) ...
…ssible Also make it a property.
…#107638) Also make it a cached property. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Explicitly exclude Lib/test/clinic.test.c when running make clinic.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Extract helper methods for formatting the signature and parameter sections, and clean up the remaining function body. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
…107790) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Reduce duplicate code in state_modulename_name()
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
…e_and_class() The hasattr(parent, "classes") check is unneeded, since 'parent' is an instance of either the Module, Class, or Clinic classes, and all of them has a "classes" attribute.
…class() (#108092) 'not hasattr(parent, "classes")' is always false, since 'parent' is an instance of either the Module, Class, or Clinic classes, and all of them has a "classes" attribute.
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. |
…ython/cpython#107770) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…ython/cpython#107770) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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
dict
instead ofOrderedDict
(gh-104683: Argument clinic: usedict
overOrderedDict
#104647)Simplify code like this by using the
str.removesuffix
andstr.removeprefix
methods, both new in Python 3.9:cpython/Tools/clinic/clinic.py
Lines 2572 to 2575 in 06eeee9
(gh-104683: Modernise
clinic.py
usingstr.removeprefix
andstr.removesuffix
#104685)Pyupgrade (run using the
--py310-plus
setting) 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
Rework Argument Clinic error handling #107468
Restructure Argument Clinic CLI #107467
Cc. @erlend-aasland
Linked PRs
dict
overOrderedDict
#104647Tools/clinic/
using pyupgrade #104684clinic.py
usingstr.removeprefix
andstr.removesuffix
#104685parse_converter()
using pattern-matching #104696clinic.py
: Improve coverage for theparse_converter
method #104729clinic.py
: Improve coverage for theparse_converter
method (#104729) #104730Parameter
andFunction
as dataclasses #106477contextlib.redirect_stdout
#106478Destination.__init__
#106652cpp.Monitor
#106698Class
andFunction
required #107289state_modulename_name()
#107340clinic
as a parameter where possible #107435filename
parameter toClinic
required #107439LandMine
class #107541DLSParser
state_foo
methods #107543self.next()
in the DSLParser #107635__repr__
functions #107667Tools/clinic
and tests forTools/clinic
#107771format_docstring()
a method onFunction
objects #107840The text was updated successfully, but these errors were encountered: