Replies: 4 comments
-
I encountered exactly the same issue after upgrading to Typer 0.16.0. Version 0.15.4 (with Click < 8.2) was working fine. |
Beta Was this translation helpful? Give feedback.
-
This issue appears to have been introduced in version 0.16.0 with click 8.2 support. < 0.16.0❯ cat test.py
#!/usr/bin/env -S uv run --python 3.13 --script
# /// script
# dependencies = [
# "click<8.2.0",
# "typer<0.16.0"
# ]
# ///
import typer
app = typer.Typer()
@app.command(no_args_is_help=True)
def main(greet: str) -> None:
print(f"Hi, {greet}")
if __name__ == "__main__":
app()
❯ ./test.py
Uninstalled 2 packages in 5ms
Installed 2 packages in 4ms
Usage: test.py [OPTIONS] GREET
╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ * greet TEXT [default: None] [required] │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --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. │
╰──────────────────────────────────────────────────────────────────────────────╯
❯ echo $?
0 == 0.16.0❯ cat test.py
#!/usr/bin/env -S uv run --python 3.13 --script
# /// script
# dependencies = [
# "click==8.2.0",
# "typer==0.16.0"
# ]
# ///
import typer
app = typer.Typer()
@app.command(no_args_is_help=True)
def main(greet: str) -> None:
print(f"Hi, {greet}")
if __name__ == "__main__":
app()
❯ ./test.py
Uninstalled 1 package in 3ms
Installed 1 package in 1ms
Usage: test.py [OPTIONS] GREET
╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ * greet TEXT [default: None] [required] │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --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. │
╰──────────────────────────────────────────────────────────────────────────────╯
Usage: test.py [OPTIONS] GREET
Try 'test.py --help' for help.
╭─ Error ──────────────────────────────────────────────────────────────────────╮
│ │
╰──────────────────────────────────────────────────────────────────────────────╯
❯ echo $?
2 |
Beta Was this translation helpful? Give feedback.
-
@tiangolo can you please check for this issue? Sir |
Beta Was this translation helpful? Give feedback.
-
@tiangolo it seems to be a problem related to this commit on click: pallets/click@d8763b9 This commit introduced an exception named click == 8.1.8 def parse_args(self, ctx: Context, args: list[str]) -> list[str]:
if not args and self.no_args_is_help and not ctx.resilient_parsing:
echo(ctx.get_help(), color=ctx.color)
ctx.exit() click >= 8.2.0 def parse_args(self, ctx: Context, args: list[str]) -> list[str]:
if not args and self.no_args_is_help and not ctx.resilient_parsing:
raise NoArgsIsHelpError(ctx) I have made a pull request that fixes that issue here #1240 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
python test.py
(using the supplied code)2
and a blank error panel will be shown0
and the error panel should not be shownOperating System
macOS
Operating System Details
Version 15.5
Typer Version
0.16.0
Python Version
Python 3.12.10
Additional Context
PR that added support (#1222) seems to have removed an assert on the exit code of a no args help here
Beta Was this translation helpful? Give feedback.
All reactions