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
@@ -596,8 +596,33 @@ def parse_no_raise(comma_separated_no_raise: str) -> list[int]:
596
596
return no_raise_codes
597
597
598
598
599
+ if TYPE_CHECKING :
600
+
601
+ class Args (argparse .Namespace ):
602
+ config : str | None = None
603
+ debug : bool = False
604
+ name : str | None = None
605
+ no_raise : str | None = None
606
+ report : bool = False
607
+ project : bool = False
608
+ commitizen : bool = False
609
+ verbose : bool = False
610
+ func : type [
611
+ commands .Init # init
612
+ | commands .Commit # commit (c)
613
+ | commands .ListCz # ls
614
+ | commands .Example # example
615
+ | commands .Info # info
616
+ | commands .Schema # schema
617
+ | commands .Bump # bump
618
+ | commands .Changelog # changelog (ch)
619
+ | commands .Check # check
620
+ | commands .Version # version
621
+ ]
622
+
623
+
599
624
def main ():
600
- parser = cli (data )
625
+ parser : argparse . ArgumentParser = cli (data )
601
626
argcomplete .autocomplete (parser )
602
627
# Show help if no arg provided
603
628
if len (sys .argv ) == 1 :
@@ -611,7 +636,7 @@ def main():
611
636
# https://github.com/commitizen-tools/commitizen/issues/429
612
637
# argparse raises TypeError when non exist command is provided on Python < 3.9
613
638
# but raise SystemExit with exit code == 2 on Python 3.9
614
- if isinstance (e , TypeError ) or ( isinstance ( e , SystemExit ) and e .code == 2 ) :
639
+ if isinstance (e , TypeError ) or e .code == 2 :
615
640
raise NoCommandFoundError ()
616
641
raise e
617
642
@@ -638,6 +663,7 @@ def main():
638
663
arguments ["extra_cli_args" ] = extra_args
639
664
640
665
conf = config .read_cfg (args .config )
666
+ args = cast ("Args" , args )
641
667
if args .name :
642
668
conf .update ({"name" : args .name })
643
669
elif not conf .path :
0 commit comments