Fix eagerness of help option generated by help_option_names
#2811
+160
−6
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.
When a help option is generated by the use of
help_option_names
setting, it loose its eagerness. This issue has an effect on the order in which parameters (and their callbacks) are processed, and breaks the evaluation order described in the documentation: https://click.palletsprojects.com/en/stable/advanced/#callback-evaluation-orderThat's because the utility method
iter_params_for_processing()
is comparing option objects, and the help option is generated on everyget_help_option()
orget_params(ctx)
call. This behavior is demonstrated by a unit-test in this PR.My solution to fix this issue consist in caching locally the auto-generated help option. This solves the issue.
I used this oportunity to clarify some documentation, and unit-test the main method responsible for the ordering of parameters.
This is more or less a follow up of #2563, which has been merged in the upcoming v8.1.8 release.
Checklist:
CHANGES.rst
summarizing the change and linking to the issue... versionchanged::
entries in any relevant code docs.pytest
andtox
, no tests failed.