Skip to content

Commit

Permalink
Add deprecated description_tooltip for backwards compatibility.
Browse files Browse the repository at this point in the history
This follows up on #2680 to help users transition to this backwards-incompatible change.
  • Loading branch information
jasongrout committed Jul 6, 2022
1 parent 763dbb9 commit 04bac14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 1 addition & 3 deletions docs/source/user_migration_guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ to wrap reads from the widget.

As part of an effort to make it possible to
[set tooltips for all widgets](https://github.com/jupyter-widgets/ipywidgets/pull/2680),
the old `description_tooltip` attribute for certain widgets was removed. Now all widgets
the old `description_tooltip` attribute for certain widgets was deprecated. Now all widgets
that inherit `DOMWidget` have the attribute `tooltip` instead.

Suggested migration: Search and replace `description_tooltip` to `tooltip`.
TBD: ipywidgets should add a `description_tooltip` keyword argument to `DescriptionWidget`s, with
a deprecation warning.

#### Selection Widgets

Expand Down
22 changes: 22 additions & 0 deletions python/ipywidgets/ipywidgets/widgets/widget_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .widget_style import Style
from .widget_core import CoreWidget
from .domwidget import DOMWidget
import warnings

@register
class DescriptionStyle(Style, CoreWidget, Widget):
Expand All @@ -24,6 +25,13 @@ class DescriptionWidget(DOMWidget, CoreWidget):
description_allow_html = Bool(False, help="Accept HTML in the description.").tag(sync=True)
style = InstanceDict(DescriptionStyle, help="Styling customizations").tag(sync=True, **widget_serialization)

def __init__(self, *args, **kwargs):
if 'description_tooltip' in kwargs:
warnings.warn("the description_tooltip argument is deprecated, use tooltip instead", DeprecationWarning)
kwargs.setdefault('tooltip', kwargs['description_tooltip'])
del kwargs['description_tooltip']
super().__init__(*args, **kwargs)

def _repr_keys(self):
for key in super()._repr_keys():
# Exclude style if it had the default value
Expand All @@ -32,3 +40,17 @@ def _repr_keys(self):
if repr(value) == '%s()' % value.__class__.__name__:
continue
yield key

@property
def description_tooltip(self):
"""The tooltip information.
.. deprecated :: 8.0.0
Use tooltip attribute instead.
"""
warnings.warn(".description_tooltip is deprecated, use .tooltip instead", DeprecationWarning)
return self.tooltip

@description_tooltip.setter
def description_tooltip(self, tooltip):
warnings.warn(".description_tooltip is deprecated, use .tooltip instead", DeprecationWarning)
self.tooltip = tooltip

0 comments on commit 04bac14

Please sign in to comment.