Duck typing means testing for methods, not using isinstance()
. What do you intend to do with the input?
If, for example, you'll accept a string, then split that string on newlines and use it otherwise like a list, test for .splitlines()
:
if hasattr(arg1, 'splitlines'):
arg1 = arg1.splitlines()
if hasattr(arg2, 'splitlines'):
arg2 = arg2.splitlines()
# now arg1 and arg2 are presumed to be lists.