You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure using typer like that on an init method is actually supported. I think having your CLI be a simple method is really to be preferred. Try putting the CLI into its own method, and then call whatever program logic you have from there, like this for example:
importtyperfromtypingimportOptionalfromdatetimeimportdatetimeclassSome:
# your class implpassdefmain(start_date: Optional[datetime] =None, stop_date: Optional[datetime] =None):
Some(start_date, stop_date).run()
if__name__=="__main__":
typer.run(main)
You can totally use a constructor as a typer command. However, it's pretty confusing! I would recommend @jonaslb's approach above instead. But if you really want to... the trick is to decorate the class instead of the initializer:
However, your code as written has a few other problems. The biggest one to me is trying to use the return value of the typer entry point. You shouldn't run any code after calling app(). Make sure all the code you want to execute is inside your command.
First Check
Commit to Help
Example Code
Description
Typer deals with the "self" argument in the class constructor "init" and does not know how to deal with that, please help!
Operating System
Windows
Operating System Details
No response
Typer Version
0.7.0
Python Version
Python 3.8.5
Additional Context
No response
The text was updated successfully, but these errors were encountered: