88from functools import partial
99from pathlib import Path
1010from types import TracebackType
11- from typing import Any
11+ from typing import TYPE_CHECKING , Any , cast
1212
1313import argcomplete
1414from decli import cli
@@ -597,8 +597,33 @@ def parse_no_raise(comma_separated_no_raise: str) -> list[int]:
597597 return no_raise_codes
598598
599599
600+ if TYPE_CHECKING :
601+
602+ class Args (argparse .Namespace ):
603+ config : str | None = None
604+ debug : bool = False
605+ name : str | None = None
606+ no_raise : str | None = None
607+ report : bool = False
608+ project : bool = False
609+ commitizen : bool = False
610+ verbose : bool = False
611+ func : type [
612+ commands .Init # init
613+ | commands .Commit # commit (c)
614+ | commands .ListCz # ls
615+ | commands .Example # example
616+ | commands .Info # info
617+ | commands .Schema # schema
618+ | commands .Bump # bump
619+ | commands .Changelog # changelog (ch)
620+ | commands .Check # check
621+ | commands .Version # version
622+ ]
623+
624+
600625def main ():
601- parser = cli (data )
626+ parser : argparse . ArgumentParser = cli (data )
602627 argcomplete .autocomplete (parser )
603628 # Show help if no arg provided
604629 if len (sys .argv ) == 1 :
@@ -612,7 +637,7 @@ def main():
612637 # https://github.com/commitizen-tools/commitizen/issues/429
613638 # argparse raises TypeError when non exist command is provided on Python < 3.9
614639 # but raise SystemExit with exit code == 2 on Python 3.9
615- if isinstance (e , TypeError ) or ( isinstance ( e , SystemExit ) and e .code == 2 ) :
640+ if isinstance (e , TypeError ) or e .code == 2 :
616641 raise NoCommandFoundError ()
617642 raise e
618643
@@ -639,6 +664,7 @@ def main():
639664 arguments ["extra_cli_args" ] = extra_args
640665
641666 conf = config .read_cfg (args .config )
667+ args = cast ("Args" , args )
642668 if args .name :
643669 conf .update ({"name" : args .name })
644670 elif not conf .path :
0 commit comments