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

Remove [default: None] for arguments and required options #465

Open
7 tasks done
taranlu-houzz opened this issue Oct 7, 2022 · 1 comment
Open
7 tasks done

Remove [default: None] for arguments and required options #465

taranlu-houzz opened this issue Oct 7, 2022 · 1 comment
Labels
feature New feature, enhancement or request investigate

Comments

@taranlu-houzz
Copy link

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

import typer


def main(
    name: str,
    option_1: str = typer.Option(
        "option_1_default",
    ),
    option_2: str = typer.Option(
        ...,
    ),
):
    print(f"Hello {name}")
    print(option_1)
    print(option_2)


if __name__ == "__main__":
    typer.run(main)

Description

In order to make the help output less cluttered, it makes sense to hide the [default: None] for arguments and required options since a value must always be passed (meaning that the default doesn't really have any use).

As an aside, I supposed that the default is sometimes used as an "example," so maybe it could make sense to add an example param that could be used for this purpose?

Wanted Solution

Current help output:

❯ pdm run python typer_issue.py --help

 Usage: typer_issue.py [OPTIONS] NAME

╭─ Arguments ──────────────────────────────────────────────────╮
│ *    name      TEXT  [default: None] [required]              │
╰──────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────╮
│    --option-1                  TEXT  [default:               │
│                                      option_1_default]       │
│ *  --option-2                  TEXT  [default: None]         │
│                                      [required]              │
│    --install-completion              Install completion for  │
│                                      the current shell.      │
│    --show-completion                 Show completion for the │
│                                      current shell, to copy  │
│                                      it or customize the     │
│                                      installation.           │
│    --help                            Show this message and   │
│                                      exit.                   │
╰──────────────────────────────────────────────────────────────╯

Desired help output:

❯ pdm run python typer_issue.py --help

 Usage: typer_issue.py [OPTIONS] NAME

╭─ Arguments ──────────────────────────────────────────────────╮
│ *    name      TEXT                  [required]              │
╰──────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────╮
│    --option-1                  TEXT  [default:               │
│                                      option_1_default]       │
│ *  --option-2                  TEXT  [required]              │
│    --install-completion              Install completion for  │
│                                      the current shell.      │
│    --show-completion                 Show completion for the │
│                                      current shell, to copy  │
│                                      it or customize the     │
│                                      installation.           │
│    --help                            Show this message and   │
│                                      exit.                   │
╰──────────────────────────────────────────────────────────────╯

Wanted Code

# No changes to the way `typer` is used

Alternatives

No response

Operating System

Linux, macOS

Operating System Details

No response

Typer Version

0.6.1

Python Version

Python 3.8.14

Additional Context

Obviously, this is a personal preference. I just feel that it helps to clean up the --help output a little bit.

@taranlu-houzz taranlu-houzz added the feature New feature, enhancement or request label Oct 7, 2022
@taranlu-houzz
Copy link
Author

I didn't think about it before, but it seems like an obvious solution to this is to just use show_default=False. Still, might be worth changing the default behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature, enhancement or request investigate
Projects
None yet
Development

No branches or pull requests

2 participants