8
8
from functools import partial
9
9
from pathlib import Path
10
10
from types import TracebackType
11
- from typing import Any
11
+ from typing import TYPE_CHECKING , Any , cast
12
12
13
13
import argcomplete
14
14
from decli import cli
@@ -597,8 +597,33 @@ def parse_no_raise(comma_separated_no_raise: str) -> list[int]:
597
597
return no_raise_codes
598
598
599
599
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
+
600
625
def main ():
601
- parser = cli (data )
626
+ parser : argparse . ArgumentParser = cli (data )
602
627
argcomplete .autocomplete (parser )
603
628
# Show help if no arg provided
604
629
if len (sys .argv ) == 1 :
@@ -612,7 +637,7 @@ def main():
612
637
# https://github.com/commitizen-tools/commitizen/issues/429
613
638
# argparse raises TypeError when non exist command is provided on Python < 3.9
614
639
# 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 :
616
641
raise NoCommandFoundError ()
617
642
raise e
618
643
@@ -639,6 +664,7 @@ def main():
639
664
arguments ["extra_cli_args" ] = extra_args
640
665
641
666
conf = config .read_cfg (args .config )
667
+ args = cast ("Args" , args )
642
668
if args .name :
643
669
conf .update ({"name" : args .name })
644
670
elif not conf .path :
0 commit comments