2222from typing import Any
2323from typing import cast
2424from typing import ContextManager
25+ from typing import NoReturn
2526from typing import TYPE_CHECKING
26- from typing import TypedDict
2727
2828import requests
2929import rich
3535from ptscripts .virtualenv import VirtualEnv
3636from ptscripts .virtualenv import VirtualEnvConfig
3737
38+ if sys .version_info < (3 , 11 ):
39+ from typing_extensions import TypedDict , NotRequired
40+ else :
41+ from typing import TypedDict , NotRequired
42+
3843try :
3944 import importlib .metadata
4045
@@ -56,14 +61,15 @@ class ArgumentOptions(TypedDict):
5661 TypedDict class documenting the acceptable keys and their types for arguments.
5762 """
5863
59- flags : list [str ]
60- help : str
61- action : str | argparse .Action
62- nargs : int | str
63- const : Any
64- choices : list [str ]
65- required : bool
66- metavar : str
64+ help : NotRequired [str ]
65+ flags : NotRequired [list [str ]]
66+ action : NotRequired [str | argparse .Action ]
67+ nargs : NotRequired [int | str ]
68+ const : NotRequired [Any ]
69+ choices : NotRequired [list [str ] | tuple [str , ...]]
70+ required : NotRequired [bool ]
71+ metavar : NotRequired [str ]
72+ default : NotRequired [Any ]
6773
6874
6975class FullArgumentOptions (ArgumentOptions ):
@@ -73,7 +79,6 @@ class FullArgumentOptions(ArgumentOptions):
7379
7480 dest : str
7581 type : type [Any ]
76- default : Any
7782
7883
7984class Context :
@@ -137,7 +142,7 @@ def error(self, *args):
137142 """
138143 self .console .log (* args , style = "log-error" , _stack_offset = 2 )
139144
140- def exit (self , status = 0 , message = None ):
145+ def exit (self , status = 0 , message = None ) -> NoReturn : # type: ignore[misc]
141146 """
142147 Exit the command execution.
143148 """
@@ -158,7 +163,7 @@ def _run(
158163 capture : bool = False ,
159164 interactive : bool = False ,
160165 ** kwargs ,
161- ) -> CompletedProcess [str ]:
166+ ) -> CompletedProcess [bytes ]:
162167 """
163168 Run a subprocess.
164169 """
@@ -181,7 +186,7 @@ def run(
181186 capture : bool = False ,
182187 interactive : bool = False ,
183188 ** kwargs ,
184- ) -> CompletedProcess [str ] | None :
189+ ) -> CompletedProcess [bytes ] :
185190 """
186191 Run a subprocess.
187192
@@ -208,9 +213,11 @@ def run(
208213 ** kwargs ,
209214 )
210215 except subprocess .CalledProcessError as exc :
211- self .error (str (exc ))
212- self .exit (exc .returncode )
213- return None
216+ self ._exit (str (exc ), exc .returncode )
217+
218+ def _exit (self , msg : str , returncode : int ) -> NoReturn :
219+ self .error (msg )
220+ self .exit (returncode )
214221
215222 @contextmanager
216223 def chdir (self , path : pathlib .Path ) -> Iterator [pathlib .Path ]:
@@ -653,7 +660,7 @@ def command(
653660 if not kwargs ["help" ].endswith ("." ):
654661 kwargs ["help" ] += "."
655662 kwargs ["help" ] += " [default: %(default)s]"
656- flags = kwargs .pop ("flags" , None ) # type: ignore[misc]
663+ flags = kwargs .pop ("flags" , None )
657664 if flags is None :
658665 flags = [f"--{ parameter .name .replace ('_' , '-' )} " ]
659666 log .debug ("Adding Command %r. Flags: %s; KwArgs: %s" , name , flags , kwargs )
@@ -708,7 +715,7 @@ def command_group(
708715 help : str ,
709716 description : str | None = None ,
710717 venv_config : VirtualEnvConfig | None = None ,
711- parent : CommandGroup | None = None ,
718+ parent : CommandGroup | str | list [ str ] | tuple [ str ] | None = None ,
712719) -> CommandGroup :
713720 """
714721 Create a new command group.
0 commit comments