Skip to content

Commit f83d6e0

Browse files
committed
Adjust stack level returned to account for it being calculated one level deeper than it is being used.
Also, make the stack level calculator private until there is a need to make it public.
1 parent 9e1b382 commit f83d6e0

File tree

1 file changed

+9
-6
lines changed
  • python/ipywidgets/ipywidgets/widgets

1 file changed

+9
-6
lines changed

python/ipywidgets/ipywidgets/widgets/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,28 @@
1111
# added in the process. For example, with the deprecation warning in the
1212
# __init__ below, the appropriate stacklevel will change depending on how deep
1313
# the inheritance hierarchy is.
14-
def external_stacklevel(internal):
14+
def _external_stacklevel(internal):
1515
"""Find the first frame that doesn't any of the given internal strings
1616
17-
The depth will be 2 at minimum in order to start checking at the caller of
17+
The depth will be 1 at minimum in order to start checking at the caller of
1818
the function that called this utility method.
1919
"""
20+
# Get the level of my caller's caller
2021
level = 2
2122
frame = sys._getframe(level)
2223
while frame and any(s in frame.f_code.co_filename for s in internal):
2324
level +=1
2425
frame = frame.f_back
25-
return level
26+
# the returned value will be used one level up from here, so subtract one
27+
return level-1
2628

2729
def deprecation(message, internal=None):
28-
"""Generate a deprecation warning targeting the first external frame
30+
"""Generate a deprecation warning targeting the first frame outside the ipywidgets library.
2931
3032
internal is a list of strings, which if they appear in filenames in the
31-
frames, the frames will also be considered internal.
33+
frames, the frames will also be considered internal. This can be useful if we know that ipywidgets
34+
is calling out to, for example, traitlets internally.
3235
"""
3336
if internal is None:
3437
internal = []
35-
warnings.warn(message, DeprecationWarning, stacklevel=external_stacklevel(internal+['ipywidgets/widgets/']))
38+
warnings.warn(message, DeprecationWarning, stacklevel=_external_stacklevel(internal+['ipywidgets/widgets/']))

0 commit comments

Comments
 (0)