planetarypy / pvl

Python implementation of PVL (Parameter Value Language)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide some additional functions for pvl.collection.Quantity objects.

rbeyer opened this issue · comments

Is your feature request related to a problem? Please describe.
Sometimes a caller will expect a particular key in the returned object, and will expect a numeric value but won't know if the value is a bare numeric value (of type float or int) or a Quantity object, but in any case won't care about the unit, and is only after the numeric value. In this case, they need to perform an isinstance() test to know whether they can use the value as-is, or if they need to call the .value attribute.

Describe the solution you'd like
Implement __float__() and __int__() functions in the pvl.collection.Quantity class, so that a caller can just call float(value) or int(value) to get the contents of Quantity.value, as needed, or a harmless conversion of a float to a float (if the value isn't a Quantity object), for example.

Describe alternatives you've considered
The alternate solution is to do nothing and continue to force type testing behavior on users, but this results in more complex downstream code. This simple change would streamline certain use cases.