Skip to content

Commit 7ae5519

Browse files
committed
tweak fix to #128, does not need to include other add_typer kwargs
1 parent 260852f commit 7ae5519

File tree

1 file changed

+35
-65
lines changed

1 file changed

+35
-65
lines changed

django_typer/management/__init__.py

Lines changed: 35 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,10 +1121,10 @@ def add_typer( # type: ignore
11211121
*,
11221122
name: t.Optional[str] = Default(None),
11231123
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),
11261126
subcommand_metavar: t.Optional[str] = Default(None),
1127-
chain: t.Union[bool, DefaultPlaceholder] = Default(False),
1127+
chain: bool = Default(False),
11281128
result_callback: t.Optional[t.Callable[..., t.Any]] = Default(None),
11291129
# Command
11301130
context_settings: t.Optional[t.Dict[t.Any, t.Any]] = Default(None),
@@ -1133,77 +1133,47 @@ def add_typer( # type: ignore
11331133
epilog: t.Optional[str] = Default(None),
11341134
short_help: t.Optional[t.Union[str, Promise]] = Default(None),
11351135
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),
11391139
# Rich settings
11401140
rich_help_panel: t.Union[str, None] = Default(None),
11411141
**kwargs: t.Any,
11421142
) -> None:
11431143
typer_instance.parent = self
11441144
typer_instance.django_command = self.django_command
11451145

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+
11511158
return super().add_typer(
11521159
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,
12071177
**kwargs,
12081178
)
12091179

0 commit comments

Comments
 (0)