Skip to content

Commit

Permalink
fix: Fix persist on magicgui method decorator (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Oct 22, 2022
1 parent 1170dd2 commit 88e598b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions magicgui/widgets/_bases/container_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(
self._list: list[Widget] = []
self._labels = labels
self._layout = layout
self._scrollable = scrollable
kwargs.setdefault("backend_kwargs", {})
kwargs["backend_kwargs"].update({"layout": layout, "scrollable": scrollable})
super().__init__(**kwargs)
Expand Down Expand Up @@ -333,9 +334,9 @@ def _load(self, path, quiet=False):
raise

for key, val in data.items():
val = pickle.loads(val)
if val != self.NO_VALUE:
with contextlib.suppress(ValueError, AttributeError):
with contextlib.suppress(ValueError, AttributeError):
val = pickle.loads(val)
if val != self.NO_VALUE:
getattr(self, key).value = val


Expand Down
8 changes: 7 additions & 1 deletion magicgui/widgets/_function_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def __init__(

sig = magic_signature(function, gui_options=param_options)
self.return_annotation = sig.return_annotation
self._tooltips = tooltips
if tooltips:
_inject_tooltips_from_docstrings(function.__doc__, sig)

Expand All @@ -164,7 +165,7 @@ def __init__(
# access attributes (like `__name__` that only function objects have).
# Mypy doesn't seem catch this at this point:
# https://github.com/python/mypy/issues/9934
name = getattr(function, "__name__", None)
name = name or getattr(function, "__name__", None)
if not name:
if hasattr(function, "func"): # partials:
f = getattr(function, "func", None)
Expand Down Expand Up @@ -372,6 +373,11 @@ def copy(self) -> FunctionGui:
auto_call=self._auto_call,
result_widget=bool(self._result_widget),
app=None,
persist=self.persist,
visible=self.visible,
tooltips=self._tooltips,
scrollable=self._scrollable,
name=self.name,
)

def __get__(self, obj, objtype=None) -> FunctionGui:
Expand Down

0 comments on commit 88e598b

Please sign in to comment.