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

Fix FunctionGui behavior as a class method #443

Merged
merged 1 commit into from
Aug 2, 2022
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
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