@@ -923,6 +923,7 @@ def __init__(
923
923
if callback :
924
924
self .name = callback .__name__
925
925
self .is_method = is_method (callback )
926
+
926
927
super ().__init__ (
927
928
name = name ,
928
929
cls = type (
@@ -1119,11 +1120,11 @@ def add_typer( # type: ignore
1119
1120
typer_instance : "Typer" ,
1120
1121
* ,
1121
1122
name : t .Optional [str ] = Default (None ),
1122
- cls : t .Type [DTGroup ] = DTGroup ,
1123
- invoke_without_command : bool = Default (False ),
1124
- no_args_is_help : bool = Default (False ),
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 ),
1125
1126
subcommand_metavar : t .Optional [str ] = Default (None ),
1126
- chain : bool = Default (False ),
1127
+ chain : t . Union [ bool , DefaultPlaceholder ] = Default (False ),
1127
1128
result_callback : t .Optional [t .Callable [..., t .Any ]] = Default (None ),
1128
1129
# Command
1129
1130
context_settings : t .Optional [t .Dict [t .Any , t .Any ]] = Default (None ),
@@ -1132,35 +1133,77 @@ def add_typer( # type: ignore
1132
1133
epilog : t .Optional [str ] = Default (None ),
1133
1134
short_help : t .Optional [t .Union [str , Promise ]] = Default (None ),
1134
1135
options_metavar : str = Default ("[OPTIONS]" ),
1135
- add_help_option : bool = Default (True ),
1136
- hidden : bool = Default (False ),
1137
- deprecated : bool = Default (False ),
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 ),
1138
1139
# Rich settings
1139
1140
rich_help_panel : t .Union [str , None ] = Default (None ),
1140
1141
** kwargs : t .Any ,
1141
1142
) -> None :
1142
1143
typer_instance .parent = self
1143
1144
typer_instance .django_command = self .django_command
1144
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.
1145
1151
return super ().add_typer (
1146
1152
typer_instance = typer_instance ,
1147
- name = name ,
1148
- cls = type ("_DTGroup" , (cls ,), {"django_command" : self .django_command }),
1149
- invoke_without_command = invoke_without_command ,
1150
- no_args_is_help = no_args_is_help ,
1151
- subcommand_metavar = subcommand_metavar ,
1152
- chain = chain ,
1153
- result_callback = result_callback ,
1154
- context_settings = context_settings ,
1155
- callback = _strip_static (callback ),
1156
- help = t .cast (str , help ),
1157
- epilog = epilog ,
1158
- short_help = t .cast (str , short_help ),
1159
- options_metavar = options_metavar ,
1160
- add_help_option = add_help_option ,
1161
- hidden = hidden ,
1162
- deprecated = deprecated ,
1163
- rich_help_panel = rich_help_panel ,
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 ,
1164
1207
** kwargs ,
1165
1208
)
1166
1209
0 commit comments