Skip to content

Commit

Permalink
fix magicgui in class
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Aug 2, 2022
1 parent a81e1ec commit 0fa8c4e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions magicgui/widgets/_function_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def __init__(
self._param_options = param_options
self._result_name = ""
self._call_count: int = 0
self._bound_instances: dict[int, FunctionGui] = {}

# a deque of Progressbars to be created by (possibly nested) tqdm_mgui iterators
self._tqdm_pbars: Deque[ProgressBar] = deque()
Expand Down Expand Up @@ -373,8 +374,6 @@ def copy(self) -> FunctionGui:
app=None,
)

_bound_instances: dict[int, FunctionGui] = {}

def __get__(self, obj, objtype=None) -> FunctionGui:
"""Provide descriptor protocol.
Expand Down
20 changes: 20 additions & 0 deletions tests/test_magicgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,26 @@ def method(self, sigma: float = 1):
assert b.method() == ("b", 5)


def test_function_binding_multiple():
class MyObject:
def __init__(self):
pass

@magicgui
def method_0(self, sigma: float = 1):
pass

@magicgui
def method_1(self, sigma: float = 2):
pass

a = MyObject()
assert MyObject.method_0 is not a.method_0
assert a.method_0 is not a.method_1
assert a.method_0.sigma.value == 1
assert a.method_1.sigma.value == 2


def test_call_count():
"""Test that a function gui remembers how many times it's been called."""

Expand Down

0 comments on commit 0fa8c4e

Please sign in to comment.