I have a search
function. This function takes 4 different parameters that can be either a list of strings or a string. For each parameter, if it's a string I convert it to a list of strings.
def search(name: Union[str, List[str], group: Union[str, List[str], ...):
if isinstance(name, str):
name = [name]
if isinstance(group, str):
group = [group]
...
As this function will be part of a framework that will be publicly released, I'm wondering if it's not better to have two different functions ? One where every parameters take a string
and the other one a list of strings
?
If the best solution is to keep only one function, what about the name of the parameters? Does they need to be plural or not...? I don't want the function to be confusing
I had a look at some other framework like django
. There filter function use a lookup attribute in addition to the default parameter like name__in=['a', 'b']
which take a list of the type of name and name='a'
that take the default type of the value. But it seems a bit complicated to put in place even if really efficient.
Does anyone encounter this in there development ? How did you manage it on your side ?