Recommended use of wraps and check for unitizing float functions with default args #1755
-
For performance and compatibility reasons, I need to write a function that accepts and returns floats, but I want to provide a "unitized" version of the function using @wraps or @check. I've run into some limitations, and I want to make sure I fully understand the intended use of these two decorators. Suppose my function is
For the unitized version, I want to enforce that
I can accomplish 1) with @check
and 2) and 3) with @wraps
But, @wraps only works properly when b is passed explicitly. If the default value is used, it raises a
So, my questions are:
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
wraps
andcheck
are not intendend to be combined. The first is intended to convert a standard function into a unit aware function. The wrapper convert the input into magnitudes of the chosen units which in turn are supplied to the wrapped function. The second only checks that the units or dimensions are right. Sowraps
converts (implicit check) and magnitud extraction.I would like to support that case.
The right way would be to make wraps accept dimensions and fix the default value.