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

Class RangeProcessor

lantz/processors.py:304–328  ·  view source on GitHub ↗

Processor to convert the units the function arguments. The syntax is equal to `Processor` except that iterables are interpreted as (low, high, step) specified ranges. Step is optional and max is included >>> conv = RangeProcessor(((1, 2, .5), )) >>> conv(1.7) 1.5

Source from the content-addressed store, hash-verified

302
303
304class RangeProcessor(Processor):
305 """Processor to convert the units the function arguments.
306
307 The syntax is equal to `Processor` except that iterables are interpreted
308 as (low, high, step) specified ranges. Step is optional and max is included
309
310 >>> conv = RangeProcessor(((1, 2, .5), ))
311 >>> conv(1.7)
312 1.5
313
314 """
315
316 @classmethod
317 def to_callable(cls, obj):
318 if not isinstance(obj, (list, tuple)):
319 raise TypeError('RangeProcessor argument must be a tuple/list '
320 'or a callable, not {}'.format(obj))
321 if not len(obj) in (1, 2, 3):
322 raise TypeError('RangeProcessor argument must be a tuple/list '
323 'with 1, 2 or 3 elements ([low,] high[, step]) '
324 'not {}'.format(len(obj)))
325
326 if len(obj) == 1:
327 return check_range_and_coerce_step(0, *obj)
328 return check_range_and_coerce_step(*obj)
329
330
331

Callers 2

rebuildMethod · 0.85
rebuildMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected