|
9 | 9 | import typing
|
10 | 10 | from contextlib import contextmanager
|
11 | 11 | from collections.abc import Iterable
|
12 |
| -import warnings |
13 | 12 | from IPython import get_ipython
|
14 | 13 | from ipykernel.comm import Comm
|
15 | 14 | from traitlets import (
|
|
19 | 18 |
|
20 | 19 | from base64 import standard_b64encode
|
21 | 20 |
|
| 21 | +from .utils import deprecation, _get_frame |
| 22 | + |
22 | 23 | from .._version import __protocol_version__, __control_protocol_version__, __jupyter_widgets_base_version__
|
23 | 24 |
|
| 25 | +import inspect |
| 26 | +TRAITLETS_FILE = inspect.getfile(HasTraits) |
| 27 | + |
24 | 28 | # Based on jupyter_core.paths.envset
|
25 | 29 | def envset(name, default):
|
26 | 30 | """Return True if the given environment variable is turned on, otherwise False
|
@@ -302,22 +306,42 @@ class Widget(LoggingHasTraits):
|
302 | 306 |
|
303 | 307 | @_staticproperty
|
304 | 308 | def widgets():
|
305 |
| - warnings.warn("Widget.widgets is deprecated.", DeprecationWarning) |
| 309 | + # Because this is a static attribute, it will be accessed when initializing this class. In that case, since a user |
| 310 | + # did not explicitly try to use this attribute, we do not want to throw a deprecation warning. |
| 311 | + # So we check if the thing calling this static property is one of the known initialization functions in traitlets. |
| 312 | + frame = _get_frame(2) |
| 313 | + if not (frame.f_code.co_filename == TRAITLETS_FILE and (frame.f_code.co_name in ('getmembers', 'setup_instance'))): |
| 314 | + deprecation("Widget.widgets is deprecated.") |
306 | 315 | return _instances
|
307 | 316 |
|
308 | 317 | @_staticproperty
|
309 | 318 | def _active_widgets():
|
310 |
| - warnings.warn("Widget._active_widgets is deprecated.", DeprecationWarning) |
| 319 | + # Because this is a static attribute, it will be accessed when initializing this class. In that case, since a user |
| 320 | + # did not explicitly try to use this attribute, we do not want to throw a deprecation warning. |
| 321 | + # So we check if the thing calling this static property is one of the known initialization functions in traitlets. |
| 322 | + frame = _get_frame(2) |
| 323 | + if not (frame.f_code.co_filename == TRAITLETS_FILE and (frame.f_code.co_name in ('getmembers', 'setup_instance'))): |
| 324 | + deprecation("Widget._active_widgets is deprecated.") |
311 | 325 | return _instances
|
312 | 326 |
|
313 | 327 | @_staticproperty
|
314 | 328 | def _widget_types():
|
315 |
| - warnings.warn("Widget._widget_types is deprecated.", DeprecationWarning) |
| 329 | + # Because this is a static attribute, it will be accessed when initializing this class. In that case, since a user |
| 330 | + # did not explicitly try to use this attribute, we do not want to throw a deprecation warning. |
| 331 | + # So we check if the thing calling this static property is one of the known initialization functions in traitlets. |
| 332 | + frame = _get_frame(2) |
| 333 | + if not (frame.f_code.co_filename == TRAITLETS_FILE and (frame.f_code.co_name in ('getmembers', 'setup_instance'))): |
| 334 | + deprecation("Widget._widget_types is deprecated.") |
316 | 335 | return _registry
|
317 | 336 |
|
318 | 337 | @_staticproperty
|
319 | 338 | def widget_types():
|
320 |
| - warnings.warn("Widget.widget_types is deprecated.", DeprecationWarning) |
| 339 | + # Because this is a static attribute, it will be accessed when initializing this class. In that case, since a user |
| 340 | + # did not explicitly try to use this attribute, we do not want to throw a deprecation warning. |
| 341 | + # So we check if the thing calling this static property is one of the known initialization functions in traitlets. |
| 342 | + frame = _get_frame(2) |
| 343 | + if not (frame.f_code.co_filename == TRAITLETS_FILE and (frame.f_code.co_name in ('getmembers', 'setup_instance'))): |
| 344 | + deprecation("Widget.widget_types is deprecated.") |
321 | 345 | return _registry
|
322 | 346 |
|
323 | 347 | @classmethod
|
|
0 commit comments