gh-104683: Argument clinic: pass clinic
as a parameter where possible
#107435
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR started off life with me wanting to get rid of this at the end of
Clinic.__init__
, which feels like an awful hack to me:cpython/Tools/clinic/clinic.py
Lines 2206 to 2207 in d0dcd27
clinic
is elsewhere set toNone
in the global namespace in two places:cpython/Tools/clinic/clinic.py
Line 2085 in d0dcd27
cpython/Tools/clinic/clinic.py
Line 5621 in d0dcd27
Unfortunately, removing this hack completely is rather difficult, due to the fact that
warn_or_fail
relies onclinic
being a global variable! Passingclinic
as a parameter towarn_or_fail
would mean that every usage ofwarn()
orfail()
would have to be updated, which would have led to a huge diff.cpython/Tools/clinic/clinic.py
Lines 155 to 171 in d0dcd27
Nonetheless, this PR still feels like a (small) improvement over the current state of affairs. In particular, by passing
clinic
as a parameter tooutput_templates
, we remove the need for anassert clinic is not None
assertion. This PR also reduces the changes that will be requir 8000 ed in the future, should we want to moveoutput_templates
into a separate module...Tools/clinic/
#104683