Skip to content
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

Add callable support to show_default #355

Closed
wants to merge 5 commits into from

Conversation

zanieb
Copy link
Contributor

@zanieb zanieb commented Feb 12, 2022

Adds callable support to show_default, allowing a Callable[[], Union[bool, str]] to be passed to dynamically determine the default to show in help messages. Closes #354.

Previously, show_default was incorrectly typed as just bool instead of Union[bool, str] on Option / OptionType. This fixes those type annotations. Closes #158.

Additionally, the default string for dynamic options was defined as default_string = _("(dynamic)") which appears to be a bug and is confusing syntax if valid. This was simplified to match the line from arguments.

I've also removed the formatted parenthesis from the displayed show_default value, as this value should be able to match the style of a real default. This is the only "breaking" change here.

I'll happily extend documentation / tests if you're willing to accept this.

@Dymstro
Copy link

Dymstro commented Apr 7, 2022

Has anyone looked at this yet?

Having to add "# type: ignore[arg-type]" everytime I use show_default with a string in an option is getting annoying

@svlandeg svlandeg added the types Type hints and type checking label Apr 21, 2022
@zanieb
Copy link
Contributor Author

zanieb commented Jun 6, 2022

Note this not only fixes the type hint for show_default but also adds callable support to show_default which is not just a type hint change. Just want to clarify since the label is a bit more narrow.

@zanieb
Copy link
Contributor Author

zanieb commented Sep 8, 2022

This conflicts with the refactor of defaults for rich_utils. Unfortunately it does not appear straight-forward to reincorporate this improvement. Given that I haven't gotten a response yet, I won't attempt to do so yet. If you're willing to accept this feature enhancement please let me know and I will attempt to resolve the conflicts.

alexreg added a commit to alexreg/typer-cloup that referenced this pull request Feb 28, 2023
alexreg added a commit to alexreg/typer-cloup that referenced this pull request Feb 28, 2023
@svlandeg svlandeg added bug Something isn't working feature New feature, enhancement or request and removed investigate labels Mar 8, 2024
@svlandeg
Copy link
Member

svlandeg commented Mar 8, 2024

[maintenance note] I'd suggest reviewing #501 first and then updating this PR to review the added feature.

@svlandeg svlandeg marked this pull request as draft March 8, 2024 14:37
@zanieb zanieb closed this Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature New feature, enhancement or request types Type hints and type checking
Projects
None yet
4 participants