MCPcopy Create free account
hub / github.com/LabPy/lantz / ToQuantityProcessor

Class ToQuantityProcessor

lantz/processors.py:205–224  ·  view source on GitHub ↗

Decorator to convert the units the function arguments. The syntax is equal to `Processor` except that strings are interpreted as units. >>> conv = ToQuantityProcessor('ms') >>> conv(Q_(1, 's')) >>> conv(1) <Quantity(

Source from the content-addressed store, hash-verified

203
204
205class ToQuantityProcessor(Processor):
206 """Decorator to convert the units the function arguments.
207
208 The syntax is equal to `Processor` except that strings are interpreted
209 as units.
210
211 >>> conv = ToQuantityProcessor('ms')
212 >>> conv(Q_(1, 's'))
213 <Quantity(1000.0, 'millisecond')>
214 >>> conv(1)
215 <Quantity(1.0, 'millisecond')>
216
217 """
218
219 @classmethod
220 def to_callable(cls, obj):
221 if isinstance(obj, (str, Q_)):
222 return convert_to(obj, on_dimensionless='ignore')
223 raise TypeError('ToQuantityProcessor argument must be a string '
224 ' or a callable, not {}'.format(obj))
225
226
227class ParseProcessor(Processor):

Callers 1

rebuildMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected