GeezerVison is showing github.com — Move `--help` option defaults from its class to its decorator by kdeldycke · Pull Request #2840 · pallets/click
Conversation
kdeldycke
commented
Jan 9, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
This is a proposal to fix #2832, which points to a subtle change in behavior of the help option introduced in 8.1.8.
The root of the problem is that by deduplicating code in 8.1.8 (see: #2563), I introduced a HelpOption class, to centralize the setup necessary to make a standard Option behave like an help option.
In #2832, a user is relying on a custom class to feed the @help_option decorator. This bypass all the custom setup made by HelpOption, and produce the discrepancy in behavior between 8.1.7 and 8.1.8.
This PR:
- Reverts back to setting up all parameters of the help option in the decorator instead of the
HelpOption class
- Aligns
@help_option implementation with the way Click is doing for the others (like @password_option, @version_option, ...)
- Removes the
click.decorators.HelpOption class as a consequence
- Adds a complete unit test to check combination of custom class and option names leads to expected results
Checklist:
- Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
- Add or update relevant docs, in the docs folder and in code.
- Add an entry in
CHANGES.rst summarizing the change and linking to the issue.
- Add
.. versionchanged:: entries in any relevant code docs.
- Run
pre-commit hooks and fix any issues.
- Run
pytest and tox, no tests failed.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
arshadperwez01 reacted with heart emoji
kdeldycke
changed the title
Allow customization of help option right from its decorator
Allow customization of help option from its decorator
Jan 9, 2025
kdeldycke
changed the title
Allow customization of help option from its decorator
Move --help option defaults from its class to its decorator
Jan 9, 2025
|
Can you rebase this on stable then we can include this in 8.1.9?
I assume we can keep this in 8.2.0, though we'll need to document it.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yes! I can rebase it to 8.1.9. I was targeting 8.2.0 as I didn't know if a 8.1.9 would see the light of day given that 8.2.0 seems imminent.
Also, something I realized, when #2563 was merged back into main branch (i.e. the future 8.2.0 release), the new HelpOption class was properly merged, but the duplicate in-place Option creation in get_help_option() was not replaced with the new HelpOption. See:
|
return Option( |
|
help_options, |
|
is_flag=True, |
|
is_eager=True, |
|
expose_value=False, |
|
callback=show_help, |
|
help=_("Show this message and exit."), |
|
) |
So I felt like this PR, by targeting main could solve both issues at the same time. What do you think?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Approved with the suggestions I just commented.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Removes `click.decorators.HelpOption` class.
Closes #2832.
# Conflicts:
# CHANGES.rst
|
I just merged the changes proposed by @davidism and rebase this PR on top of main.
All tests are passing but the typing workflow job, which is also failing for the same reason on the vanilla main branch. Same thing for the pre-commit.yaml workflow that is failing for reasons not related to this PR.
So unless you have other issues to point to, I think this PR is ready to be merged upstream.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
help output
Help text formatting, layout, and --help rendering
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.
|