@@ -1121,10 +1121,10 @@ def add_typer( # type: ignore
1121
1121
* ,
1122
1122
name : t .Optional [str ] = Default (None ),
1123
1123
cls : t .Type [DTGroup ] = Default (DTGroup ),
1124
- invoke_without_command : t . Union [ bool , DefaultPlaceholder ] = Default (False ),
1125
- no_args_is_help : t . Union [ bool , DefaultPlaceholder ] = Default (False ),
1124
+ invoke_without_command : bool = Default (False ),
1125
+ no_args_is_help : bool = Default (False ),
1126
1126
subcommand_metavar : t .Optional [str ] = Default (None ),
1127
- chain : t . Union [ bool , DefaultPlaceholder ] = Default (False ),
1127
+ chain : bool = Default (False ),
1128
1128
result_callback : t .Optional [t .Callable [..., t .Any ]] = Default (None ),
1129
1129
# Command
1130
1130
context_settings : t .Optional [t .Dict [t .Any , t .Any ]] = Default (None ),
@@ -1133,77 +1133,47 @@ def add_typer( # type: ignore
1133
1133
epilog : t .Optional [str ] = Default (None ),
1134
1134
short_help : t .Optional [t .Union [str , Promise ]] = Default (None ),
1135
1135
options_metavar : str = Default ("[OPTIONS]" ),
1136
- add_help_option : t . Union [ bool , DefaultPlaceholder ] = Default (True ),
1137
- hidden : t . Union [ bool , DefaultPlaceholder ] = Default (False ),
1138
- deprecated : t . Union [ bool , DefaultPlaceholder ] = Default (False ),
1136
+ add_help_option : bool = Default (True ),
1137
+ hidden : bool = Default (False ),
1138
+ deprecated : bool = Default (False ),
1139
1139
# Rich settings
1140
1140
rich_help_panel : t .Union [str , None ] = Default (None ),
1141
1141
** kwargs : t .Any ,
1142
1142
) -> None :
1143
1143
typer_instance .parent = self
1144
1144
typer_instance .django_command = self .django_command
1145
1145
1146
- # there is some disconnect between how typer resolves these parameters when used
1147
- # natively and how they're resolved when used in the django-typer interface. The
1148
- # typer interface uses the info object as a fallback for default parameters without
1149
- # manually doing the check in add_typer, but we have to do it here to make this work
1150
- # with the django-typer interface. Not sure why.
1146
+ assert cls # cls must be interface compatible with DTGroup
1147
+
1148
+ group_class = (
1149
+ type (
1150
+ "_DTGroup" ,
1151
+ (cls ,),
1152
+ {"django_command" : self .django_command },
1153
+ )
1154
+ if not isinstance (cls , DefaultPlaceholder )
1155
+ else typer_instance .info .cls
1156
+ )
1157
+
1151
1158
return super ().add_typer (
1152
1159
typer_instance = typer_instance ,
1153
- name = name
1154
- if not isinstance (name , DefaultPlaceholder )
1155
- else typer_instance .info .name ,
1156
- cls = type ("_DTGroup" , (cls ,), {"django_command" : self .django_command })
1157
- if not isinstance (cls , DefaultPlaceholder )
1158
- else typer_instance .info .cls ,
1159
- invoke_without_command = invoke_without_command
1160
- if not isinstance (invoke_without_command , DefaultPlaceholder )
1161
- else typer_instance .info .invoke_without_command ,
1162
- no_args_is_help = no_args_is_help
1163
- if not isinstance (no_args_is_help , DefaultPlaceholder )
1164
- else typer_instance .info .no_args_is_help ,
1165
- subcommand_metavar = subcommand_metavar
1166
- if not isinstance (subcommand_metavar , DefaultPlaceholder )
1167
- else typer_instance .info .subcommand_metavar ,
1168
- chain = chain
1169
- if not isinstance (chain , DefaultPlaceholder )
1170
- else typer_instance .info .chain ,
1171
- result_callback = result_callback
1172
- if not isinstance (result_callback , DefaultPlaceholder )
1173
- else typer_instance .info .result_callback ,
1174
- context_settings = context_settings
1175
- if not isinstance (context_settings , DefaultPlaceholder )
1176
- else typer_instance .info .context_settings ,
1177
- callback = _strip_static (callback )
1178
- if not isinstance (callback , DefaultPlaceholder )
1179
- else typer_instance .info .callback ,
1180
- help = t .cast (str , help )
1181
- if not isinstance (help , DefaultPlaceholder )
1182
- else typer_instance .info .help ,
1183
- epilog = epilog
1184
- if not isinstance (epilog , DefaultPlaceholder )
1185
- else typer_instance .info .epilog ,
1186
- short_help = t .cast (
1187
- str ,
1188
- short_help
1189
- if not isinstance (short_help , DefaultPlaceholder )
1190
- else typer_instance .info .short_help ,
1191
- ),
1192
- options_metavar = options_metavar
1193
- if not isinstance (options_metavar , DefaultPlaceholder )
1194
- else typer_instance .info .options_metavar ,
1195
- add_help_option = add_help_option
1196
- if not isinstance (add_help_option , DefaultPlaceholder )
1197
- else typer_instance .info .add_help_option ,
1198
- hidden = hidden
1199
- if not isinstance (hidden , DefaultPlaceholder )
1200
- else typer_instance .info .hidden ,
1201
- deprecated = deprecated
1202
- if not isinstance (deprecated , DefaultPlaceholder )
1203
- else typer_instance .info .deprecated ,
1204
- rich_help_panel = rich_help_panel
1205
- if not isinstance (rich_help_panel , DefaultPlaceholder )
1206
- else typer_instance .info .rich_help_panel ,
1160
+ name = name ,
1161
+ cls = group_class ,
1162
+ invoke_without_command = invoke_without_command ,
1163
+ no_args_is_help = no_args_is_help ,
1164
+ subcommand_metavar = subcommand_metavar ,
1165
+ chain = chain ,
1166
+ result_callback = result_callback ,
1167
+ context_settings = context_settings ,
1168
+ callback = _strip_static (callback ),
1169
+ help = t .cast (str , help ),
1170
+ epilog = epilog ,
1171
+ short_help = t .cast (str , short_help ),
1172
+ options_metavar = options_metavar ,
1173
+ add_help_option = add_help_option ,
1174
+ hidden = hidden ,
1175
+ deprecated = deprecated ,
1176
+ rich_help_panel = rich_help_panel ,
1207
1177
** kwargs ,
1208
1178
)
1209
1179
0 commit comments