107107)
108108from .utils import _command_context , traceback_config , with_typehint
109109
110+ if sys .version_info < (3 , 9 ):
111+ from typing_extensions import ParamSpec
112+ else :
113+ from typing import ParamSpec
114+
115+
110116VERSION = (1 , 0 , 2 )
111117
112118__title__ = "Django Typer"
126132 "model_parser_completer" ,
127133]
128134
135+ P = ParamSpec ("P" )
136+ R = t .TypeVar ("R" )
137+
129138
130139def model_parser_completer (
131140 model_cls : t .Type [Model ],
@@ -532,7 +541,9 @@ class GroupFunction(Typer):
532541 django_command_cls : t .Type ["TyperCommand" ]
533542 _callback : t .Callable [..., t .Any ]
534543
535- def __get__ (self , obj , obj_type = None ):
544+ def __get__ (
545+ self , obj : t .Optional ["TyperCommand" ], _ = None
546+ ) -> t .Union ["GroupFunction" , MethodType ]:
536547 """
537548 Our Typer app wrapper also doubles as a descriptor, so when
538549 it is accessed on the instance, we return the wrapped function
@@ -590,8 +601,8 @@ def command( # type: ignore
590601 deprecated : bool = False ,
591602 # Rich settings
592603 rich_help_panel : t .Union [str , None ] = Default (None ),
593- ** kwargs ,
594- ):
604+ ** kwargs : t . Dict [ str , t . Any ] ,
605+ ) -> t . Callable [[ t . Callable [ P , R ]], t . Callable [ P , R ]] :
595606 """
596607 A function decorator that creates a new command and attaches it to this group.
597608 This is a passthrough to Typer.command() and the options are the same, except
@@ -637,21 +648,29 @@ def command1(self):
637648 :param rich_help_panel: the rich help panel to use - if rich is installed
638649 this can be used to group commands into panels in the help output.
639650 """
640- return super ().command (
641- name = name ,
642- cls = cls ,
643- context_settings = context_settings ,
644- help = help ,
645- epilog = epilog ,
646- short_help = short_help ,
647- options_metavar = options_metavar ,
648- add_help_option = add_help_option ,
649- no_args_is_help = no_args_is_help ,
650- hidden = hidden ,
651- deprecated = deprecated ,
652- rich_help_panel = rich_help_panel ,
653- ** kwargs ,
654- )
651+
652+ def decorator (f : t .Callable [P , R ]) -> t .Callable [P , R ]:
653+ return super ( # pylint: disable=super-with-arguments
654+ GroupFunction , self
655+ ).command (
656+ name = name ,
657+ cls = cls ,
658+ context_settings = context_settings ,
659+ help = help ,
660+ epilog = epilog ,
661+ short_help = short_help ,
662+ options_metavar = options_metavar ,
663+ add_help_option = add_help_option ,
664+ no_args_is_help = no_args_is_help ,
665+ hidden = hidden ,
666+ deprecated = deprecated ,
667+ rich_help_panel = rich_help_panel ,
668+ ** kwargs ,
669+ )(
670+ f
671+ )
672+
673+ return decorator
655674
656675 def group (
657676 self ,
@@ -673,8 +692,8 @@ def group(
673692 deprecated : bool = Default (False ),
674693 # Rich settings
675694 rich_help_panel : t .Union [str , None ] = Default (None ),
676- ** kwargs ,
677- ):
695+ ** kwargs : t . Dict [ str , t . Any ] ,
696+ ) -> t . Callable [[ t . Callable [..., t . Any ]], "GroupFunction" ] :
678697 """
679698 Create a new subgroup and attach it to this group. This is like creating a new
680699 Typer app and adding it to a parent Typer app. The kwargs are passed through
@@ -721,7 +740,7 @@ def subcommand(self):
721740 this can be used to group commands into panels in the help output.
722741 """
723742
724- def create_app (func : t .Callable [..., t .Any ]):
743+ def create_app (func : t .Callable [..., t .Any ]) -> GroupFunction :
725744 grp = GroupFunction ( # type: ignore
726745 name = name ,
727746 cls = cls ,
@@ -769,8 +788,8 @@ def initialize(
769788 deprecated : bool = Default (False ),
770789 # Rich settings
771790 rich_help_panel : t .Union [str , None ] = Default (None ),
772- ** kwargs ,
773- ):
791+ ** kwargs : t . Dict [ str , t . Any ] ,
792+ ) -> t . Callable [[ t . Callable [ P , R ]], t . Callable [ P , R ]] :
774793 """
775794 A function decorator that creates a Typer_
776795 `callback <https://typer.tiangolo.com/tutorial/commands/callback/>`_. This
@@ -863,7 +882,7 @@ def divide(
863882 this can be used to group commands into panels in the help output.
864883 """
865884
866- def decorator (func : t .Callable [..., t . Any ]) :
885+ def decorator (func : t .Callable [P , R ]) -> t . Callable [ P , R ] :
867886 setattr (
868887 func ,
869888 "_typer_callback_" ,
@@ -899,7 +918,7 @@ def decorator(func: t.Callable[..., t.Any]):
899918
900919def command ( # pylint: disable=keyword-arg-before-vararg
901920 name : t .Optional [str ] = None ,
902- * args ,
921+ * ,
903922 cls : t .Type [TyperCommandWrapper ] = TyperCommandWrapper ,
904923 context_settings : t .Optional [t .Dict [t .Any , t .Any ]] = None ,
905924 help : t .Optional [str ] = None , # pylint: disable=redefined-builtin
@@ -912,8 +931,8 @@ def command( # pylint: disable=keyword-arg-before-vararg
912931 deprecated : bool = False ,
913932 # Rich settings
914933 rich_help_panel : t .Union [str , None ] = Default (None ),
915- ** kwargs ,
916- ):
934+ ** kwargs : t . Dict [ str , t . Any ] ,
935+ ) -> t . Callable [[ t . Callable [ P , R ]], t . Callable [ P , R ]] :
917936 """
918937 A function decorator that creates a new command and attaches it to the root
919938 command group. This is a passthrough to
@@ -970,13 +989,12 @@ def other_command(self):
970989 this can be used to group commands into panels in the help output.
971990 """
972991
973- def decorator (func : t .Callable [..., t . Any ]) :
992+ def decorator (func : t .Callable [P , R ]) -> t . Callable [ P , R ] :
974993 setattr (
975994 func ,
976995 "_typer_command_" ,
977996 lambda cmd , _name = None , _help = None , ** extra : cmd .typer_app .command (
978997 name = name or _name ,
979- * args ,
980998 cls = type ("_AdaptedCommand" , (cls ,), {"django_command" : cmd }),
981999 context_settings = context_settings ,
9821000 help = help or _help ,
@@ -1017,8 +1035,8 @@ def group(
10171035 deprecated : bool = Default (False ),
10181036 # Rich settings
10191037 rich_help_panel : t .Union [str , None ] = Default (None ),
1020- ** kwargs ,
1021- ):
1038+ ** kwargs : t . Dict [ str , t . Any ] ,
1039+ ) -> t . Callable [[ t . Callable [..., t . Any ]], GroupFunction ] :
10221040 """
10231041 A function decorator that creates a new subgroup and attaches it to the root
10241042 command group. This is like creating a new Typer_ app and adding it to a parent
@@ -1083,7 +1101,7 @@ def subcommand(self):
10831101 this can be used to group commands into panels in the help output.
10841102 """
10851103
1086- def create_app (func : t .Callable [..., t .Any ]):
1104+ def create_app (func : t .Callable [..., t .Any ]) -> GroupFunction :
10871105 grp = GroupFunction ( # type: ignore
10881106 name = name ,
10891107 cls = cls ,
0 commit comments