def accept_singleton(expected_type, position=1):
 @decorator
 def wrapper(function, *args, **kw):
  if isinstance(args[position], expected_type):
   args = list(args)
   args[position] = [args[position]]
   args = tuple(args)
  return function(*args, **kw)
 return wrapper

def accept_singleton ( expected_type , position = 1 ) : @ decorator def wrapper ( function , * args , ** kw ) : if isinstance ( args [ position ] , expected_type ) : args = list ( args ) args [ position ] = [ args [ position ] ] args = tuple ( args ) return function ( * args , ** kw ) return wrapper
allows a function expecting a list to accept a single item as well .