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

[BUG] Error: Got unexpected extra argument #233

Closed
prakashjayy opened this issue Feb 7, 2021 · 10 comments
Closed

[BUG] Error: Got unexpected extra argument #233

prakashjayy opened this issue Feb 7, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@prakashjayy
Copy link

prakashjayy commented Feb 7, 2021

Describe the bug

Error: Got unexpected extra argument while calling a function using typer.

Write here a clear and concise description of what the bug is.

I have specified 3 arguments for a function and getting the above error while using typer. my code looks like this.

  • main.py
import typer 
app = typer.Typer()

@app.command()
def generate_csv(
    cfg: str,
    csv_loc: str,
    weights_locs: str,
):
    typer.echo(cfg)
    typer.echo(csv_loc)

if __name__ == "__main__":
    app()
  • run python infer.py generate-csv "xxx" "yyy" "lightning_logs/version_3/checkpoints/epoch=18-step=10164.ckpt"

Error

Usage: infer.py [OPTIONS] CFG CSV_LOC WEIGHTS_LOCS
Try 'infer.py --help' for help.

Error: Got unexpected extra argument (lightning_logs/version_3/checkpoints/epoch=18-step=10164.ckpt)

however this error disappears and it works normally if I add another function as below and wrap it with typer.

```python
import typer 
app = typer.Typer()

@app.command()
def test():
    print("working fine")

@app.command()
def generate_csv(
    cfg: str,
    csv_loc: str,
    weights_locs: str,
):
    typer.echo(cfg)
    typer.echo(csv_loc)

if __name__ == "__main__":
    app()
  • run python infer.py generate-csv "xxxx" "yyyy" "lightning_logs/version_3/checkpoints/epoch=18-step=10164.ckpt"

output:

xxxx  
yyyy

Environment

  • I am using ubuntu 16.04 and Anaconda python 3.6 environment.
  • I am using typer==0.3.0
@prakashjayy prakashjayy added the bug Something isn't working label Feb 7, 2021
@daddycocoaman
Copy link
Contributor

When you only have one command, like in your first example, there is no need to specify the name of the command you want to run. Typer sees that you only have one command to run, therefore the user must be intending to run that command.

So your first example should just be python infer.py "xxx" "yyy" "lightning_logs/version_3/checkpoints/epoch=18-step=10164.ckpt"

@prakashjayy
Copy link
Author

Thanks @daddycocoaman.

@schenock
Copy link

When you only have one command, like in your first example, there is no need to specify the name of the command you want to run. Typer sees that you only have one command to run, therefore the user must be intending to run that command.

So your first example should just be python infer.py "xxx" "yyy" "lightning_logs/version_3/checkpoints/epoch=18-step=10164.ckpt"

I don't think that's a good "design choice". Very confusing and weird. Why not support both cases when only 1 app.command wrapped func?

@JavierLopezT
Copy link

When you only have one command, like in your first example, there is no need to specify the name of the command you want to run. Typer sees that you only have one command to run, therefore the user must be intending to run that command.

So your first example should just be python infer.py "xxx" "yyy" "lightning_logs/version_3/checkpoints/epoch=18-step=10164.ckpt"

This should be on the first page of the documentation

@zhipengwa
Copy link

When you only have one command, like in your first example, there is no need to specify the name of the command you want to run. Typer sees that you only have one command to run, therefore the user must be intending to run that command.
So your first example should just be python infer.py "xxx" "yyy" "lightning_logs/version_3/checkpoints/epoch=18-step=10164.ckpt"

I don't think that's a good "design choice". Very confusing and weird. Why not support both cases when only 1 app.command wrapped func?

I want to second this comment, it costs me entire day to figure out the root cause.

@samibtorres
Copy link

I had the same problem for a while and found the page where it says if there is only one command defined in the app, but still want to use its name, there needs to be a callback defined : https://typer.tiangolo.com/tutorial/commands/one-or-multiple/

@zanieb
Copy link
Contributor

zanieb commented Sep 27, 2023

It'd be great so support both cases e.g. my_app and my_app my_command, I also was very confused by this during development of a prototype application. Could this be opened again?

@GiorgioSgl
Copy link

GiorgioSgl commented Nov 23, 2023

I lost a lot of a time to encounter the problem! I don't understand why this design choose. I agree with @zanieb support both cases is the best option.

@nguyenvulong
Copy link

nguyenvulong commented Mar 20, 2024

I just learned Typer half an hour ago and found 2 terrible designs

  • automatic conversion from underscore to hyphen (inherited from Click)
  • this. Should have let us use python main.py func opt in case there's a single command.

https://github.com/BrianPugh/cyclopts fixed the latter with app.default() but did not "fix" the first one either.

@BrianPugh
Copy link

@nguyenvulong please open up an issue in the cyclopts repo for the first point; we can probably figure something out. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants