-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
Bad argument help for type of optional argument #438
Comments
You can manually specify the metavar like this: import typer
from typing import Optional
def main(name: Optional[str] = typer.Argument(None, metavar='name')):
if name:
typer.echo(f'Name: {name}')
if __name__ == '__main__':
typer.run(main) |
Yes, but this is erasing the problem. |
I would say that issue is caused by logic in here: https://github.com/tiangolo/typer/blob/7f44e6db6267efa87918e8700212de41a7fbdc3e/typer/rich_utils.py#L367-L377 To reiterate the exact issue - following code: import sys, typer
sys.argv[1:] = ['--help']
def example(*,
arg1: int,
arg2: int = 42,
arg3: int = typer.Argument(...),
arg4: int = typer.Argument(42),
arg5: int = typer.Option(...),
arg6: int = typer.Option(42),
arg7: int = typer.Argument(42, metavar='metaarg7'),
arg8: int = typer.Argument(42, metavar='ARG8'),
):
pass
typer.run(example) Produces following help message:
The usage example works as intended and documented - for each argument a metavar is displayed. The issue is in rest of help message. As the code is written - the second column is designed to contain metavar. But due to condition While this condition is core of the issue it probably was added quite reasonably - because metavar column is not really useful. Similarly to OP, I would also prefer changing this column to just always contain type. |
First Check
Commit to Help
Example Code
Description
For optional arguments Typer shows their metavar instead of type in argument help. For above example instead of
TEXT
we get[NAME]
in argument help.Operating System
macOS
Operating System Details
No response
Typer Version
0.6.1
Python Version
3.10
Additional Context
No response
The text was updated successfully, but these errors were encountered: