16
16
from ..params .options .interactive import InteractiveOption
17
17
from .verdi import VerdiCommandGroup
18
18
19
+ if t .TYPE_CHECKING :
20
+ from click .decorators import FC
21
+
19
22
__all__ = ('DynamicEntryPointCommandGroup' ,)
20
23
21
24
@@ -44,11 +47,11 @@ def cmd_create():
44
47
45
48
def __init__ (
46
49
self ,
47
- command : t . Callable ,
50
+ command : click . Command ,
48
51
entry_point_group : str ,
49
52
entry_point_name_filter : str = r'.*' ,
50
- shared_options : list [t . Callable [[ t . Any ], t . Any ] ] | None = None ,
51
- ** kwargs ,
53
+ shared_options : list [FC ] | None = None ,
54
+ ** kwargs : t . Any ,
52
55
):
53
56
super ().__init__ (** kwargs )
54
57
self ._command = command
@@ -88,7 +91,7 @@ def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None
88
91
command = super ().get_command (ctx , cmd_name )
89
92
return command
90
93
91
- def call_command (self , ctx , cls , non_interactive , ** kwargs ) :
94
+ def call_command (self , ctx : click . Context , cls : t . Any , non_interactive : bool , ** kwargs : t . Any ) -> t . Any :
92
95
"""Call the ``command`` after validating the provided inputs."""
93
96
from pydantic import ValidationError
94
97
@@ -116,13 +119,13 @@ def create_command(self, ctx: click.Context, entry_point: str) -> click.Command:
116
119
command .__doc__ = cls .__doc__
117
120
return click .command (entry_point )(self .create_options (entry_point )(command ))
118
121
119
- def create_options (self , entry_point : str ) -> t .Callable :
122
+ def create_options (self , entry_point : str ) -> t .Callable [[ FC ], FC ] :
120
123
"""Create the option decorators for the command function for the given entry point.
121
124
122
125
:param entry_point: The entry point.
123
126
"""
124
127
125
- def apply_options (func ) :
128
+ def apply_options (func : FC ) -> FC :
126
129
"""Decorate the command function with the appropriate options for the given entry point."""
127
130
func = options .NON_INTERACTIVE ()(func )
128
131
func = options .CONFIG_FILE ()(func )
@@ -143,7 +146,7 @@ def apply_options(func):
143
146
144
147
return apply_options
145
148
146
- def list_options (self , entry_point : str ) -> list [t .Callable [[t . Any ], t . Any ]]:
149
+ def list_options (self , entry_point : str ) -> list [t .Callable [[FC ], FC ]]:
147
150
"""Return the list of options that should be applied to the command for the given entry point.
148
151
149
152
:param entry_point: The entry point.
@@ -207,7 +210,7 @@ def list_options(self, entry_point: str) -> list[t.Callable[[t.Any], t.Any]]:
207
210
return options_ordered
208
211
209
212
@staticmethod
210
- def create_option (name , spec : dict ) -> t .Callable [[t . Any ], t . Any ]:
213
+ def create_option (name : str , spec : dict [ str , t . Any ] ) -> t .Callable [[FC ], FC ]:
211
214
"""Create a click option from a name and a specification."""
212
215
is_flag = spec .pop ('is_flag' , False )
213
216
name_dashed = name .replace ('_' , '-' )
0 commit comments