GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Move `--help` option defaults from its class to its decorator by kdeldycke · Pull Request #2840 · pallets/click

Conversation

@kdeldycke

@kdeldycke kdeldycke commented Jan 9, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

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
All reactions
  • ❤️ 1 reaction
@kdeldycke kdeldycke mentioned this pull request Jan 9, 2025
Regression: Help option subclassing no longer works with verion 8.1.8 #2832
Closed
@kdeldycke 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 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
kdeldycke added a commit to kdeldycke/click-extra that referenced this pull request Jan 10, 2025
@kdeldycke
Set --help/-h as defaults for @help_option decorator
b77007d
Remove custom HelpOption class.

Refs:
pallets/click#2563
pallets/click#2832
pallets/click#2840
@AndreasBackx

AndreasBackx commented Jan 12, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke

kdeldycke commented Jan 15, 2025

Copy link
Copy Markdown
Collaborator Author

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:

click/src/click/core.py

Lines 1028 to 1035 in 8fcf9b0

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

davidism
davidism reviewed Mar 17, 2025
View reviewed changes
Comment thread src/click/core.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

davidism
davidism reviewed Mar 17, 2025
View reviewed changes
Comment thread src/click/core.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@davidism

davidism commented Mar 17, 2025

Copy link
Copy Markdown
Member

Approved with the suggestions I just commented.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke
Allow customization of help option right from its decorator.
0b7a9ac
Removes `click.decorators.HelpOption` class.

Closes #2832.

# Conflicts:
#	CHANGES.rst
@kdeldycke

kdeldycke commented Mar 18, 2025

Copy link
Copy Markdown
Collaborator Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Rowlando13
Rowlando13 merged commit c9f7d9d into pallets:main Mar 18, 2025
@kdeldycke
kdeldycke deleted the help-option-fix branch March 19, 2025 12:13
@kdeldycke kdeldycke mentioned this pull request Mar 27, 2025
Merge stable into main; Release 8.2.0 #2873
Merged
6 tasks done
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 2, 2025
@Rowlando13 Rowlando13 added this to the 8.2.0 milestone May 10, 2025
@kdeldycke kdeldycke added the help output Help text formatting, layout, and --help rendering label Aug 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@davidism davidism davidism left review comments

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

Projects

None yet

Milestone

8.2.0

Development

Successfully merging this pull request may close these issues.

Regression: Help option subclassing no longer works with verion 8.1.8

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@kdeldycke @AndreasBackx @davidism @Rowlando13
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.