Skip to content

how to use typer on class method __init__ with self argument, got this error: Error: Missing argument 'SELF'. #539

Open
@fbenavides69

Description

@fbenavides69

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

app = typer.Typer()


class some:
    @app.command()
    def __init__(self, start_date: Optional[str] = None, stop_date: Optional[str] = None) -> None:
        self.start = start_date
        self.stop = stop_date

    def run():
        print(f"{self.start} - {self.stop}")

if __name__ == "__main__":
    dc = app.run(some())
    dc.run()

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion or problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions