Skip to content

Commit

Permalink
Support multiple results
Browse files Browse the repository at this point in the history
  • Loading branch information
Routhleck committed Dec 3, 2024
1 parent efcfd75 commit 21d59a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions brainunit/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4492,6 +4492,12 @@ def new_f(*args, **kwds):
newkeyset[n] = v

result = f(**newkeyset)
if isinstance(result, tuple):
assert isinstance(au["result"], tuple), "The return value of the function is a tuple, but the decorator expected a single unit."
result = tuple(
Quantity(r, unit=au["result"][i]) if isinstance(au["result"][i], Unit) else r
for i, r in enumerate(result)
)
if "result" in au:
specific_unit = au["result"]
if specific_unit == bool:
Expand Down
10 changes: 10 additions & 0 deletions brainunit/_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,16 @@ def c_function(a, b):
with pytest.raises(TypeError):
c_function(1 * mV, 1)

# Multiple results
@u.handle_units(result=(second, volt))
def d_function():
return 5, 3

# Should work (returns second)
assert d_function()[0] == 5 * second
assert d_function()[1] == 3 * volt



def test_str_repr():
"""
Expand Down

0 comments on commit 21d59a7

Please sign in to comment.