Skip to content

Add type annotations for the arguments of the CLI entry point #1477

Closed
@gbaian10

Description

@gbaian10

Description

In the CLI entry point (cli.py), all properties inside args are unknown to the IDE, which makes it harder for new developers to read and understand the code.

This is especially problematic when trying to quickly identify which function args.func actually refers to.

Possible Solution

I suggest adding type hints to clarify which attributes correspond to which functions. Since this change only involves adding type annotations, it will not affect the end-user's runtime behavior. In theory, such a change is safe.

Additional context

I suggest adding the following content.

class Args(argparse.Namespace):
    config: str | None = None
    debug: bool = False
    name: str | None = None
    no_raise: str | None = None
    report: bool = False
    project: bool = False
    commitizen: bool = False
    verbose: bool = False
    func: type[
        commands.Init  # init
        | commands.Commit  # commit (c)
        | commands.ListCz  # ls
        | commands.Example  # example
        | commands.Info  # info
        | commands.Schema  # schema
        | commands.Bump  # bump
        | commands.Changelog  # changelog (ch)
        | commands.Check  # check
        | commands.Version  # version
    ]

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions