Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some more py3-related warnings and deprecations #2655

Merged
merged 2 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions ipywidgets/widgets/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,11 @@ def _yield_abbreviations_for_parameter(param, kwargs):
"""Get an abbreviation for a function parameter."""
name = param.name
kind = param.kind
ann = param.annotation
default = param.default
not_found = (name, empty, empty)
if kind in (Parameter.POSITIONAL_OR_KEYWORD, Parameter.KEYWORD_ONLY):
if name in kwargs:
value = kwargs.pop(name)
elif ann is not empty:
warn("Using function annotations to implicitly specify interactive controls is deprecated. Use an explicit keyword argument for the parameter instead.", DeprecationWarning)
value = ann
elif default is not empty:
value = default
else:
Expand Down Expand Up @@ -246,7 +242,7 @@ def update(self, *args):
except Exception as e:
ip = get_ipython()
if ip is None:
self.log.warn("Exception in interact callback: %s", e, exc_info=True)
self.log.warning("Exception in interact callback: %s", e, exc_info=True)
else:
ip.showtraceback()
finally:
Expand Down
113 changes: 2 additions & 111 deletions ipywidgets/widgets/tests/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from traitlets import TraitError
from ipywidgets import (interact, interact_manual, interactive,
interaction, Output)
from ipython_genutils.py3compat import annotate

#-----------------------------------------------------------------------------
# Utility stuff
Expand Down Expand Up @@ -249,7 +248,8 @@ def test_iterable_tuple():
check_widgets(c, lis=d)

def test_mapping():
from collections import Mapping, OrderedDict
from collections.abc import Mapping
from collections import OrderedDict
class TestMapping(Mapping):
def __init__(self, values):
self.values = values
Expand All @@ -276,115 +276,6 @@ def items(self):
)
check_widgets(c, lis=d)


def test_defaults():
@annotate(n=10)
def f(n, f=4.5, g=1):
pass

c = interactive(f)
check_widgets(c,
n=dict(
cls=widgets.IntSlider,
value=10,
),
f=dict(
cls=widgets.FloatSlider,
value=4.5,
),
g=dict(
cls=widgets.IntSlider,
value=1,
),
)

def test_default_values():
@annotate(n=10, f=(0, 10.), g=5, h=OrderedDict([('a',1), ('b',2)]), j=['hi', 'there'])
def f(n, f=4.5, g=1, h=2, j='there'):
pass

c = interactive(f)
check_widgets(c,
n=dict(
cls=widgets.IntSlider,
value=10,
),
f=dict(
cls=widgets.FloatSlider,
value=4.5,
),
g=dict(
cls=widgets.IntSlider,
value=5,
),
h=dict(
cls=widgets.Dropdown,
options=OrderedDict([('a',1), ('b',2)]),
value=2
),
j=dict(
cls=widgets.Dropdown,
options=('hi', 'there'),
value='there'
),
)

def test_default_out_of_bounds():
@annotate(f=(0, 10.), h={'a': 1}, j=['hi', 'there'])
def f(f='hi', h=5, j='other'):
pass

c = interactive(f)
check_widgets(c,
f=dict(
cls=widgets.FloatSlider,
value=5.,
),
h=dict(
cls=widgets.Dropdown,
options={'a': 1},
value=1,
),
j=dict(
cls=widgets.Dropdown,
options=('hi', 'there'),
value='hi',
),
)

def test_annotations():
@annotate(n=10, f=widgets.FloatText())
def f(n, f):
pass

c = interactive(f)
check_widgets(c,
n=dict(
cls=widgets.IntSlider,
value=10,
),
f=dict(
cls=widgets.FloatText,
),
)

def test_priority():
@annotate(annotate='annotate', kwarg='annotate')
def f(kwarg='default', annotate='default', default='default'):
pass

c = interactive(f, kwarg='kwarg')
check_widgets(c,
kwarg=dict(
cls=widgets.Text,
value='kwarg',
),
annotate=dict(
cls=widgets.Text,
value='annotate',
),
)

def test_decorator_kwarg(clear_display):
with patch.object(interaction, 'display', record_display):
@interact(a=5)
Expand Down