commitizen-tools/commitizen

Add type annotations for the arguments of the CLI entry point

Closed this issue · 1 comments

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

Resolved by PR #1479