-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Calling the method e.g. like this will make it fail with a NameError as neither processing_option nor dimension_select will be defined then:
get_processing_settings(
dimension="channel",
selection="something_unexpected",
value=1,
range_end=None
)python-imcflibs/src/imcflibs/imagej/bdv.py
Lines 708 to 759 in 26f64c9
| def get_processing_settings(dimension, selection, value, range_end): | |
| """Generate processing strings for selected dimension and processing mode. | |
| Generate the processing option and dimension selection strings that | |
| correspond to the selected processing mode and the given dimension | |
| selection. | |
| Parameters | |
| ---------- | |
| dimension : {`angle`, `channel`, `illumination`, `tile`, `timepoint`} | |
| The dimension selection to use. | |
| selection : {`single`, `multiple`, `range`} | |
| The *selector* name ("processing mode"), used to derive how the | |
| generated string needs to be assembled according to the given dimension | |
| and value / range settings. | |
| value : str, int, list of int or list of str | |
| The list of input dimensions, the first input dimension of a range or a | |
| single dimension value in case `selection == "single"` (e.g. for | |
| selecting a single channel). | |
| range_end : int or None | |
| Contains the end of the range if need be. | |
| Returns | |
| ------- | |
| tuple of str | |
| processing_option, dimension_select | |
| """ | |
| if selection == "single": | |
| processing_option = SINGLE % dimension | |
| dimension_select = "processing_" + dimension + "=[" + dimension + " %s]" % value | |
| if selection == "multiple": | |
| processing_option = MULTIPLE % dimension | |
| dimension_list = "" | |
| for dimension_name in value: | |
| dimension_list += dimension + "_%s " % dimension_name | |
| dimension_select = dimension_list.rstrip() | |
| if selection == "range": | |
| processing_option = RANGE % dimension | |
| dimension_select = ( | |
| "process_following_" | |
| + dimension | |
| + "s=%s-%s" | |
| % ( | |
| value, | |
| range_end, | |
| ) | |
| ) | |
| return processing_option, dimension_select |
Two obvious ways to deal with this:
- Either have a "default path" in the conditional blocks, i.e. by using the
if selection == "single"part without the condition. - Or (preferred, best practice) validate the
selectionparameter (anddimensionas well for that matter) to check if it contains any of the values described in the docstring and return aValueErrorif not.
Reactions are currently unavailable