Skip to content

Commit 5406e41

Browse files
committed
Support multi-layer wrapped functions.
1 parent 401ba13 commit 5406e41

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

click_option_group/_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
get_callback_and_params,
1313
get_fake_option_name,
1414
raise_mixing_decorators_error,
15+
resolve_wrappers
1516
)
1617

1718

@@ -182,7 +183,7 @@ def decorator(func):
182183
def get_options(self, ctx: click.Context) -> ty.Dict[str, GroupedOption]:
183184
"""Returns the dictionary with group options
184185
"""
185-
return self._options.get(ctx.command.callback, {})
186+
return self._options.get(resolve_wrappers(ctx.command.callback), {})
186187

187188
def get_option_names(self, ctx: click.Context) -> ty.List[str]:
188189
"""Returns the list with option names ordered by addition in the group

click_option_group/_helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def get_callback_and_params(func) -> ty.Tuple[abc.Callable, ty.List[click.Option
2323
else:
2424
params = getattr(func, '__click_params__', [])
2525

26+
func = resolve_wrappers(func)
2627
return func, params
2728

2829

@@ -37,3 +38,8 @@ def raise_mixing_decorators_error(wrong_option: click.Option, callback: abc.Call
3738
"Grouped options must not be mixed with regular parameters while adding by decorator. "
3839
f"Check decorator position for {error_hint} option in '{callback.__name__}'."
3940
))
41+
42+
43+
def resolve_wrappers(f):
44+
"""Get the underlying function behind any level of function wrappers."""
45+
return resolve_wrappers(f.__wrapped__) if hasattr(f, "__wrapped__") else f

0 commit comments

Comments
 (0)