You need to fix your design to make all the actions of the function truly correct.
Ralph Waldo Emerson. "Stupid consistency is the hobgoblin of little minds, adored by little statesmen, philosophers and theologians."
We are not talking about a stupid sequence. You have a design issue based on inconsistent use of this feature.
Option 1. Do not call convert_val( x ) , where x is a non-list. Do it. convert_val( [x] ) . Do not correct your function, correct all the places in which your function is used. Consistency helps reduce errors.
Option 2: Modify the convert_val construct to use multiple positional arguments. This is not well generalized.
def convert_val( *args ): whatever it supposed to do to the arguments.
Then convert_val( *someList ) all the places where you provided the list convert_val( *someList ) . This is good, and may be closer to your intentions.
Note.
You can find your design errors with the warnings module.
def convert_val( arg ): if isinstance( arg, collections.Sequence ): return convert_val_list( arg ) else: warnings.warn( "Fix this" ) return convert_val_list( [arg] )[0] def convert_val_list( arg ): assert isinstance( arg, collections.Sequence ) the original processing
After fixing all design issues, you can do it
convert_val = convert_val_list
And remove the original function.
source share