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 pre 0.2.0 deprecation warnings #138

Merged
merged 6 commits into from
Jan 31, 2021
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
2 changes: 1 addition & 1 deletion docs/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ argument "`min`":

```{code-cell} python
---
tags: [warns]
:tags: [raises-exception]
---
@magicgui(a_string={'min': 10})
def whoops(a_string: str = 'Hi there'):
Expand Down
59 changes: 0 additions & 59 deletions examples/OLD_napari_image_arithmetic.py

This file was deleted.

46 changes: 0 additions & 46 deletions examples/OLD_napari_param_sweep.py

This file was deleted.

50 changes: 0 additions & 50 deletions examples/OLD_snells_law.py

This file was deleted.

24 changes: 2 additions & 22 deletions magicgui/widgets/_bases/categorical_widget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import inspect
import warnings
from enum import EnumMeta
from typing import Any, Callable

Expand Down Expand Up @@ -103,26 +101,8 @@ def choices(self, choices: ChoicesType):
_choices = choices["choices"]
str_func = choices["key"]
elif not isinstance(choices, EnumMeta) and callable(choices):
try:
_choices = choices(self)
except TypeError:

n_params = len(inspect.signature(choices).parameters)
if n_params > 1:
warnings.warn(
"\n\nAs of magicgui 0.2.0, when providing a callable to "
"`choices`, the\ncallable may accept only a single positional "
"argument (which will\nbe an instance of "
"`magicgui.widgets._bases.CategoricalWidget`),\nand must "
"return an iterable (the choices to show).\nFunction "
f"'{choices.__module__}.{choices.__name__}' accepts {n_params} "
"arguments.\nIn the future, this will raise an exception.\n",
FutureWarning,
)
# pre 0.2.0 API
_choices = choices(self.native, self.annotation) # type: ignore
else:
raise
_choices = choices(self)

else:
_choices = choices
if not all(isinstance(i, tuple) and len(i) == 2 for i in _choices):
Expand Down
10 changes: 0 additions & 10 deletions magicgui/widgets/_bases/container_widget.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import inspect
import warnings
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -254,15 +253,6 @@ def reset_choices(self, event=None):
if hasattr(widget, "reset_choices"):
widget.reset_choices() # type: ignore

def refresh_choices(self, event=None):
"""Alias for reset_choices [DEPRECATED: use reset_choices]."""
warnings.warn(
"\n`ContainerWidget.refresh_choices` is deprecated and will be removed in a"
" future version, please use `ContainerWidget.reset_choices` instead.",
FutureWarning,
)
return self.reset_choices(event)

@property
def __signature__(self) -> MagicSignature:
"""Return a MagicSignature object representing the current state of the gui."""
Expand Down
9 changes: 3 additions & 6 deletions magicgui/widgets/_bases/widget.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import inspect
import warnings
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any, ForwardRef, Optional, Type, Union

Expand Down Expand Up @@ -63,11 +62,9 @@ def __init__(
# for ipywidgets API compatibility
label = label or extra.pop("description", None)
if extra:
warnings.warn(
f"\n\n{self.__class__.__name__}.__init__() got unexpected "
f"keyword arguments {set(extra)!r}.\n"
"In the future this will raise an exception\n",
FutureWarning,
raise TypeError(
f"{type(self).__name__} got an unexpected "
f"keyword argument: {', '.join(extra)}"
)

_prot = self.__class__.__annotations__["_widget"]
Expand Down
27 changes: 0 additions & 27 deletions magicgui/widgets/_function_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import inspect
import re
import warnings
from collections import deque
from contextlib import contextmanager
from types import FunctionType
Expand Down Expand Up @@ -198,18 +197,6 @@ def reset_call_count(self) -> None:
"""Reset the call count to 0."""
self._call_count = 0

def __getattr__(self, value):
"""Catch deprecated _name_changed attribute."""
if value.endswith("_changed"):
widget_name = value.replace("_changed", "")
warnings.warn(
"\nThe `<name>_changed` signal has been removed in magicgui 0.2.0.\n"
f"Use 'widget.{widget_name}.changed' instead of 'widget.{value}'",
FutureWarning,
)
return getattr(self, widget_name).changed
return super().__getattr__(value)

# def __delitem__(self, key: Union[int, slice]):
# """Delete a widget by integer or slice index."""
# raise AttributeError("can't delete items from a FunctionGui")
Expand Down Expand Up @@ -340,20 +327,6 @@ def __set__(self, obj, value):
"""Prevent setting a magicgui attribute."""
raise AttributeError("Can't set magicgui attribute")

def Gui(self, show=False):
"""Create a widget instance [DEPRECATED]."""
warnings.warn(
"\n\nCreating a widget instance with `my_function.Gui()` is deprecated,\n"
"the magicgui decorator now returns a widget instance directly, so you\n"
"should simply use the function itself as a magicgui widget, or call\n"
"`my_function.show(run=True)` to run the application.\n"
"In a future version, the `Gui` attribute will be removed.\n",
FutureWarning,
)
if show:
self.show()
return self


class MainFunctionGui(FunctionGui[_R], MainWindow):
"""Container of widgets as a Main Application Window."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def test_doc_code_cells(fname, globalns=globals()):
if "warns" in header.group():
with pytest.warns(None):
exec(cell, globalns)
continue
continue
if "raises-exception" in header.group():
with pytest.raises(Exception):
exec(cell, globalns)
continue
continue
exec(cell, globalns)


Expand Down
6 changes: 3 additions & 3 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ def test_custom_widget_fails():
assert "Missing methods: {'_mgui_set_tooltip'}" in str(err)


def test_extra_kwargs_warn():
def test_extra_kwargs_error():
"""Test that unrecognized kwargs gives a FutureWarning."""
with pytest.warns(FutureWarning) as wrn:
with pytest.raises(TypeError) as wrn:
widgets.Label(unknown_kwarg="hi")
assert "unexpected keyword arguments" in str(wrn[0].message)
assert "unexpected keyword argument" in str(wrn)


def test_autocall_no_runtime_error():
Expand Down