yt-project / unyt

Handle, manipulate, and convert data with units in Python
https://unyt.readthedocs.io
BSD 3-Clause "New" or "Revised" License
364 stars 49 forks source link

Allow dimension-checking of multiple return values #435

Closed db434 closed 1 year ago

db434 commented 1 year ago

Extend the @returns decorator so it can handle functions with multiple return values.

Example:

>>> @returns(length, length/time**2)
... def f(a, v):
...     return a * v, v / a
...
>>> res = f(a= 2 * u.s, v = 3 * u.m/u.s)
>>> print(*res)
6 m 1.5 m/s**2

I think I've followed everything in CONTRIBUTING, but please let me know if I've missed anything.

neutrinoceros commented 1 year ago

This seems like a good idea ! I don't have time to review in detail right now but I'll be back very shortly. In the mean time, I suggest updating this decorator's documentation to reflect the new possibility. Thanks for your work !

db434 commented 1 year ago

Thanks for taking a look.

In the mean time, I suggest updating this decorator's documentation to reflect the new possibility.

I think I've done this already - is there anywhere else that you would suggest changing?

neutrinoceros commented 1 year ago

You've updated the docstring (that's great !), but I'm talking about the narrative documentation. Namely, I'd expect some update to docs/usage.rst

neutrinoceros commented 1 year ago

Thank you for following through ! automated testing seems to have caught some syntax error in the docs. I suggest you try to run tox locally to make sure everything is okay, because currently we need to manually approve your tests to run every time you push (this is a security measure against bad agents, it only applies to new contributors !).

db434 commented 1 year ago

Sorry for this CI spam - I've struggled to get all of the tests running locally. Hopefully this is the last time..!

db434 commented 1 year ago

I believe those tests are here. Is there anything else you're looking for?

Thanks for your patience with this!

neutrinoceros commented 1 year ago

Oh I somehow missed them, even better ! I have no further request.