Cython fixes for optional range argument.
Throw an exception if a layer is neither a range or task layer.