Skip to content

Commit 93ac9fb

Browse files
committed
Move frame gathering into error code path
This avoids unnecessary slowdowns (~300ms) which are mainly seen in auto completion.
1 parent 4c370e3 commit 93ac9fb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

click_option_group/_decorators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ def group(self,
107107
if not issubclass(cls, OptionGroup):
108108
raise TypeError("'cls' must be a subclass of 'OptionGroup' class.")
109109

110-
frame = inspect.getouterframes(inspect.currentframe())[self._outer_frame_index]
111-
lineno = frame.lineno
112-
113110
def decorator(func):
114111
callback, params = get_callback_and_params(func)
115112

116113
if callback not in self._decorating_state:
114+
frame = inspect.getouterframes(inspect.currentframe())[self._outer_frame_index]
115+
lineno = frame.lineno
116+
117117
with_name = f' "{name}"' if name else ''
118118
warnings.warn((f'The empty option group{with_name} was found (line {lineno}) '
119119
f'for "{callback.__name__}". The group will not be added.'),

0 commit comments

Comments
 (0)